CursorLoader and Finalizing cursor that has not been deactivated or closed error

烈酒焚心 提交于 2019-12-04 21:46:45

Not sure if any of this is related to your problem, but here goes:

  1. I wouldn't call getSupportLoaderManager().initLoader() before you create your adapters. Maybe it works, but if onLoadFinished() gets called before the adapters are created, it seems to me like it could cause issues.

  2. Why are you calling getContentResolver().notifyChange() in your setScreen() method? As far as I understand, notifyChange() is for notification that data in the content provider has changed, but it doesn't look to me like you're changing anything. From my limited use of content providers, I only call ContentResolver.notifyChange() within the content provider class itself. See its use here for an example: http://developer.android.com/resources/samples/NotePad/src/com/example/android/notepad/NotePadProvider.html

  3. This is really nitpicky, but in onCreateLoader() you could probably do something like this:

    return new CursorLoader(
    instead of creating unused references.
  4. Lastly, to get to the actual question, the only time I've seen that error is when I have an open cursor that I haven't closed. Since CursorLoader handles the cursor life cycle, I'd look to make sure there isn't anywhere else in your app where you have an open cursor, like from calling getContentResolver().query() or querying a database directly.

  5. If none of the above works, maybe you could split the data you're handling with separate CursorLoaders into separate CursorProviders.

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