Question

I have a piece of code like the following in say Activity A :

private static final int LOADER_ID = 0x200;

protected void onCreate(Bundle b) {
  ...
  ...
  Loader previousLoader = getSupportLoaderManager().getLoader(LOADER_ID);
  ...
  ...
}

Observation 1 :

User changes the orientation of the device while Activity A is displayed - previousLoader is not null.

Observation 2 :

User navigates from Activity A to Activity B, changes the orientation of the device while viewing Activity B and Hits the back button - previousLoader is null.

I was not sure why previousLoader is null in Case 2. The whole idea of using loader is to avoid data loading everytime during configuration changes. The Activity A has a set of fragments which relies on the previously loaded data to work faithfully. Because of this problem the activity is crashing. That is a different issue but I'm interested in knowing why getLoader fails to return the previously used loader.

The order of lifecycle methods called were as expected : ie.,

OnPause, OnSaveInstanceState, OnStop, OnDestroy, OnCreate, OnStart, OnRestoreInstanceState and OnResume

In my case Activity B was any activity which handles ACTION_VIEW

Was it helpful?

Solution

This looks like a bug in the framework which is yet to be fixed. The android developers thread has a discussion on this : https://groups.google.com/forum/?fromgroups#!topic/android-developers/DbKL6PVyhLI.

The exact same issue is described here : https://groups.google.com/d/msg/android-developers/DbKL6PVyhLI/OMuWhcCMWo0J.

There is an open ticket in the google android site to address this issue : https://code.google.com/p/android/issues/detail?id=20791

I hope the problem is resolved in one of the upcoming releases.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top