Tag: android syncadapter

检查应用程序是在前台还是后台运行(使用同步适配器)

我知道这是一个重复的问题,但我已经看遍了所有的地方,找不到解决方案,适合我这么… 我有一个从TMDB API获取电影数据的应用程序,它使用同步适配器通过页面获取它,基本上它运行的很好,除非当应用程序打开时用户不在第一页时同步适配器的定期同步被运行,所以我的选择是强制更新电影列表,并将用户发送到列表的顶部,这是完全不好的经验,所以不被视为一种选择,或者我可以检查应用程序是否正在运行,无论是在前台或在应用程序堆栈,它是不可见的用户仍然在运行,所以最好的我可以通过搜索得到这段代码: public static boolean isAppRunning(final Context context, final String packageName) { final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); final List procInfos = activityManager.getRunningAppProcesses(); if (procInfos != null) { for (final ActivityManager.RunningAppProcessInfo processInfo : procInfos) { if (processInfo.processName.equals(packageName)) return true; } } return false; } 但无论什么原因,它不能正常工作,看到应用程序运行,即使我通过刷卡杀死它,起初我以为是因为我有一个同步适配器,可以被视为应用程序运行,所以我用另一个进程它在清单中使用 android:process=”:service” 但它没有工作 还想过在活动的onStart和onStop中使用variables,但不能保证在应用程序关闭或死亡时将调用onStop,以避免此方法 这是我的manifest.xml 那么,有什么想法? 提前致谢

SyncAdapter中的Singleton Room数据库触发LiveData

我努力在我的SyncAdapter使用Room作为单例。 我使用Kotlin。 我的房间课 @Database(entities = [(Product::class)], version = 1, exportSchema = false) abstract class AppDatabase : RoomDatabase() { abstract fun productDao(): ProductDao companion object { @Volatile private var INSTANCE: AppDatabase? = null fun getInstance(context: Context) : AppDatabase = INSTANCE ?: synchronized(this) { INSTANCE ?: buildDatabase(context.applicationContext) .also {INSTANCE = it} } private fun buildDatabase(context: Context) = […]

IllegalArgumentException:不支持addAccount

我按照这个描述来添加我的同步适配器。 但有一个小错误:-( 当我打开设置 – >帐户 – >添加帐户,并选择我的帐户我收到此错误消息 java.lang.IllegalArgumentException: addAccount not supported at android.accounts.AccountManager.convertErrorToException(AccountManager.java:2147) at android.accounts.AccountManager.-wrap0(AccountManager.java) at android.accounts.AccountManager$AmsTask$Response.onError(AccountManager.java:1993) at android.accounts.IAccountManagerResponse$Stub.onTransact(IAccountManagerResponse.java:69) at android.os.Binder.execTransact(Binder.java:453) 看起来这个崩溃来自将Authenticator Java类转换为Kotlin类。 Java类像这样锁定 public class Authenticator extends AbstractAccountAuthenticator { private final Context mContext; // Simple constructor public Authenticator(Context context) { super(context); mContext = context; } // Editing properties is not supported @Override public Bundle […]

这是用图像(Android / Kotlin)离线保存大量数据的最佳方法。

请建议使用图片(Kotlin)离线保存数据的最佳方法。 该应用程序需要离线运行,以便从Web服务获得10,000个产品。 我需要离线保存图像。 请分享您的宝贵评论。 选项 同步适配器 运行服务以保存数据 问题可能会面临 抓取数据时应用程序可能关闭。