0

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

4

1 回答 1

2

前段时间,当我刚刚涉足 Android 编程时,我问了这个问题,我想我会为任何好奇的人分享我的发现。当我按照教程实现自定义 ContentProvider 时,我看到它notifyChange (Uri uri, ContentObserver observer)update(),insert()delete()方法之后使用。什么都不知道,我还调用notifyChange了我的 ContentProvider。这导致了我无法弄清楚的无限同步循环等问题。有一个重载方法:notifyChange (Uri uri, ContentObserver observer, boolean syncToNetwork)我当时就知道,但我永远无法弄清楚如何使用它,因为我notifyChange的 ContentProvider 中调用了我的方法。这实际上是一个简单的解决方法。我所要做的就是notifyChange (uri, null, false)不在我的 ContentProvider 中调用,而是在通过 ContentResolver 调用这些方法之后调用getContentResolver().insert()等等

我希望这可以帮助别人。

于 2013-09-06T20:32:32.120 回答