I have a main Activity A that uses a CursorLoader to query a DB. This I create in the activity onCreate() method:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
getSupportLoaderManager().initLoader(LOADER_MEASUREMENTS, null, A.this);
}
Activity A also implements the 3 callbacks for the CursorLoader:
public Loader<Cursor> onCreateLoader(int loaderId, Bundle args)
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor)
public void onLoaderReset(Loader<Cursor> loader)
When I rotate the device, I see the correct lifecycle methods run:
A.onPause()
A.onStop()
A.onDestroy()
A.onCreate() <-- re-connect to existing loader, onCreateLoader() not called
A.onLoadFinished()
A.onStart()
A.onResume()
Then I open a sub-Activity B and rotate my device. When I finish B and return to Activity A I see the following run:
B.onPause()
A.onLoaderReset() <- why does this run?
A.onDestroy()
A.onCreate()
A.onCreateLoader() <- now runs as loader is null
A.onStart()
...
Why is my loader reset because I had Activity B open and did a device rotate? Just to add that Activity B has nothing to do with the DB or the CursorLoader.