我有一个同步适配器用于我的DB和在应用程序的使用的某些点,它需要现在来同步数据块。我想触发同步适配器,如果同步时弹出,然后重新建立同步时间(即4小时这个现在同步事件)。
I have a sync adapter for my DB and at certain points in the application usage, it needs to sync the DB now. I would like to trigger the sync adapter as if its sync-time popped and then re-establish the sync time (i.e., 4 hours from this 'sync now" event).
我觉得(未测试)一个更好的解决方案是在ContentResolver的已定义。
I think (not tested) a better solution is already defined in the ContentResolver.
ContentResolver.requestSync(account, authority, extras);
所以人们不妨做到以下几点:
so one might do the following:
AccountManager am = AccountManager.get(context);
Account account = null;
am.getAccountsByType(mytype);
for(Account a : accounts) {
if (am.getUserData(account, key)) {
account = a;
break;
}
}
Bundle extras = new Bundle();
extras.putString(EXTRA_mystuff, myvalue);
ContentResolver.requestSync(account, authority, extras)