立即运行我的Android SyncAdapter。

立即运行我的Android SyncAdapter。,android,Android,我已经实现了一个SyncAdapter,就像这里所描述的那样(使用一个虚拟帐户),并且使用了我的一个内容提供者(每个表有一个)。据我所知,同步代码很好。如果我进入“设置->帐户”,选择我创建的虚拟帐户,然后系统运行“立即同步”菜单项我的适配器。它所做的只是记录它被调用的事实 但尝试从我自己的“立即同步”菜单选项运行它(请参见下面的“我的主要活动”)却不行。如果我们有WiFi连接,有没有办法让同步适配器立即运行 请试试这个 Bundle b = new Bundle(); // D

我已经实现了一个SyncAdapter,就像这里所描述的那样(使用一个虚拟帐户),并且使用了我的一个内容提供者(每个表有一个)。据我所知,同步代码很好。如果我进入“设置->帐户”,选择我创建的虚拟帐户,然后系统运行“立即同步”菜单项我的适配器。它所做的只是记录它被调用的事实

但尝试从我自己的“立即同步”菜单选项运行它(请参见下面的“我的主要活动”)却不行。如果我们有WiFi连接,有没有办法让同步适配器立即运行

请试试这个

    Bundle b = new Bundle();
    // Disable sync backoff and ignore sync preferences. In other words...perform sync NOW!
    b.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    b.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
    ContentResolver.requestSync(
            GenericAccountService.GetAccount(),      // Sync account
            FeedContract.CONTENT_AUTHORITY, // Content authority
            b);                                      // Extras
    Bundle b = new Bundle();
    // Disable sync backoff and ignore sync preferences. In other words...perform sync NOW!
    b.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    b.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
    ContentResolver.requestSync(
            GenericAccountService.GetAccount(),      // Sync account
            FeedContract.CONTENT_AUTHORITY, // Content authority
            b);                                      // Extras