【问题标题】:Sync Adapter not calling onCreate同步适配器未调用 onCreate
【发布时间】:2015-06-19 06:33:01
【问题描述】:

我们需要启动 Sync Adapter 服务还是隐式启动框架?我已经在同步适配器服务的ConstructoronCreateonDestroy 上添加了日志,当我启动应用程序时,我在 logcat 中看不到日志。

但是当我做活动时onCreate

Intent serviceIntent = new Intent(context, SyncService.class);
context.startService(serviceIntent);

我看到了日志。

请建议。

干杯, 拉杰

【问题讨论】:

    标签: android android-intent android-activity android-service android-syncadapter


    【解决方案1】:

    同步适配器通过调用显式启动:

    ContentResolver.requestSync(ACCOUNT, AUTHORITY, null);
    

    或类似方法:

    ContentResolver.addPeriodicSync(
                ACCOUNT,
                AUTHORITY,
                Bundle.EMPTY,
                SYNC_INTERVAL);
    

    https://developer.android.com/training/sync-adapters/running-sync-adapter.html

    我强烈推荐这本书,尤其是前 200 页http://www.wrox.com/WileyCDA/WroxTitle/Enterprise-Android-Programming-Android-Database-Applications-for-the-Enterprise.productCd-1118183495.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-20
      • 1970-01-01
      • 1970-01-01
      • 2013-11-24
      相关资源
      最近更新 更多