如何code A"现在&QUOT同步;运行在Android? [英] How to code a "sync now" operation on Android?
本文介绍了如何code A"现在&QUOT同步;运行在Android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个同步适配器用于我的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)
这篇关于如何code A"现在&QUOT同步;运行在Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文