如何在Android上编码“立即同步”操作?
-
11-10-2019 - |
题
我有一个用于DB的同步适配器,在应用程序使用中的某些时刻,它需要立即同步DB。我想触发同步适配器的同步时间弹出,然后重新建立同步时间(即距离此“同步现在”事件4个小时)。
解决方案
我认为(未测试)在ContentResolver中已经定义了更好的解决方案。
ContentResolver.requestSync(account, authority, extras);
因此,可能会做以下操作:
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)
不隶属于 StackOverflow