Using a Cursor returned from a LoaderManager in an AsyncTask

删除回忆录丶 提交于 2019-12-05 06:01:51

Is it possible to somehow flag the cursor to prevent it from being closed from the UI thread?

No (well, not without re-writing the internal APIs).

Is it possible to notify the manager that the cursor is still in use?

Same answer as above.

Is it possible to clone it so that the cloned instance doesn't get closed by the manager?

This sounds kind of messy... and there is still the chance that the LoaderManager closes the cursor before you are able to finish cloning it.

Is there a better solution?

Yes. Query a new cursor instead of trying to reusing the one that you pass to the LoaderManager.

Man, I am facing the very same problem. The way is to cancel the asynctask in the activity's onDestroy method.

private YourAsyncTask asyncTask

@Override
protected void onDestroy(){
    super.onDestroy();
    asyncTask.cancel(true);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!