infinite sync loop syncadapter

2019-06-13 17:14发布

I have the same problem stated here: Android SyncAdapter stuck in infinite sync loop

But after trying to implement the notifychange (Uri uri, ContentObserver observer, boolean syncToNetwork) in onPerformSync, I realized that I didn't know how to get the ContentObserver that I needed (which is defined and passed in in the main activity)

Any tips?

EDIT 1:

like this person First time sync loops indefinitely

I found that ContentResolver.cancelSync(account, authority); will work as well, but if anyone has a better solution...please let me know!

EDIT 2:

I followed the advice from this post Android SyncAdapter Automatically Initialize Syncing

after stepping through with the debugger, I confirmed that SyncToNetwork is most definitely false when it is passed into notifyChange, yet the infinite sync continues without the cancelSync...still no permanent solution

1条回答
Deceive 欺骗
2楼-- · 2019-06-13 17:49

I asked this question some time ago when I was just dipping my toes into Android programming, and I figured I'd share what I found for anyone who's curious. When I was following tutorials to implement a custom ContentProvider, I saw that notifyChange (Uri uri, ContentObserver observer) was used after the update(), insert() and delete() methods. Not really knowing anything, I also called notifyChange in my ContentProvider. This led to problems like infinite sync loops that I just could not figure out. There is an overloaded method: notifyChange (Uri uri, ContentObserver observer, boolean syncToNetwork) which I knew about then, but I could never figure out how to use it because my notifyChange was being called in my ContentProvider. This was actually an easy fix. All I had to do was call notifyChange (uri, null, false) not in my ContentProvider, but rather, after calling those methods through the ContentResolver getContentResolver().insert() etc.

I hope this helps someone.

查看更多
登录 后发表回答