CursorLoader is canceled when an action is paused

I have CursorLoaderone that provides data for ListFragment. I have a notification mechanism configured correctly in mine ContentProviderwith:

cursor.setNotificationUri(getContext().getContentResolver(), uri);

and

getContext().getContentResolver().notifyChange(uri, null)

When I select a list item, a new child item opens Activityand in onCreate()this ActivityI make a request that changes the details of the item.

I know that the notification is triggered, and is CursorLoaderre-requesting the content provider.

The problem I am facing is that sometimes mine CursorLoaderis canceled because the parent is Activitypaused (or stopped) and onLoadFinished()never called.

When CursorLoadercanceled, even if I restarted the bootloader onResume() ListFragment, I do not see changes in the data:

@Override
public void onResume() {
    super.onResume();
    getLoaderManager().initLoader(URL_LOADER, null, this);
}

I am using the v4 support library.

I assume that the CursorLoaderparent updates Activity, even if it is in the background. Do I need to restart the bootloader when resuming ListFragment?

(edit)

I forgot to mention that I create and run the bootloader with ListFragment.

After some debugging, I found that when stopped, the ListFragmentloader manager cancels all current loaders for the fragment.

, , db , . , , . ListFragment , . , onResume().

, db 10 , ( ), .

- , (restartCursor()) ?

+4
1

getSupportLoaderManager() getLoaderManager(), FragmentActivity. :

getActivity().getSupportLoaderManager().initLoader(id, null, this);
0

Source: https://habr.com/ru/post/1543727/


All Articles