更新时间:2023-11-20 23:49:52
我已经找到一种解决方案是沟 ContentResolver的
完全,并实现自己的广播。基本上,在同步适配器添加此,在年底 onPerformSync
:
One solution that I have found is to ditch the ContentResolver
completely, and implement my own broadcast. Basically, add this in the sync adapter, at the end of onPerformSync
:
Intent i = new Intent(SYNC_FINISHED);
sendBroadcast(i);
这在活动:
@Override
protected void onResume() {
super.onResume();
registerReceiver(syncFinishedReceiver, new IntentFilter(DataSyncService.SYNC_FINISHED));
}
@Override
protected void onPause() {
super.onPause();
unregisterReceiver(syncFinishedReceiver);
}
private BroadcastReceiver syncFinishedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.d(Const.TAG, "Sync finished, should refresh nao!!");
}
};
这似乎工作得很好,但我希望能找到一些在SDK时,同步完成后直接通知我。
This seems to work just fine, however I was hoping to find something in the SDK that directly notify me when a sync is finished.