LoaderCallbacks.onLoadFinished not called if activity is not active

﹥>﹥吖頭↗ 提交于 2020-01-07 05:30:29

问题


I have two activities who read the same database table. In activity A I have an AsyncTaskLoader and LoaderCallbacks objects with the following onLoadFinished code (in Scala):

def onLoadFinished(loader: CursorLoader, cursor: Cursor) = {

  android.util.Log.d(TAG, "got results")
  cursor.setNotificationUri(ct.getContentResolver, observePath)

  cursor registerContentObserver new ContentObserver(new Handler) {
    override def onChange(selfChange: Boolean) = {
      android.util.Log.d(TAG, "change registered")
      if (null != loader) loader.onContentChanged
    }
    override def deliverSelfNotifications = true
  }
}

Now, if I go to activity B, update database there and call this:

getContentResolver.notifyChange(observePath, null)

then onLoadFinished in activity A is never called although I do get "change registered" output in console.
But if I set a few seconds delay so that I have time to return to activity A before the code above is executed, then onLoadFinished is called normally.

It seems LoaderCallbacks methods are somehow dependent on the host activity being active but I don't want that, I want onLoadFinished to be called even if activity A is in background. How can I achieve that?

来源:https://stackoverflow.com/questions/35609166/loadercallbacks-onloadfinished-not-called-if-activity-is-not-active

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!