I have one bootloader used in activity. I can start the bootloader and it is called onLoadFinished. When I update the data and call onContentChanged in the loader, I see that loadInBackground and deliverResult . Here the trail stops. I do not get any callback to onLoadFinished .
If I recreate an action (otherwise a change of orientation or restart), then it will behave the same.
I am using the bootloader and bootloader manager support-v4.
My SharedPreferenceLoader based on CommonsWare loader :
public class SharedPreferencesLoader extends AsyncTaskLoader<SharedPreferences> implements SharedPreferences.OnSharedPreferenceChangeListener { private SharedPreferences prefs = null; private static final String TAG = SharedPreferencesLoader.class.getSimpleName(); public SharedPreferencesLoader(Context context) { super(context); } @Override public SharedPreferences loadInBackground() { Log.v(TAG, "wol: load in background"); prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); prefs.registerOnSharedPreferenceChangeListener(this); return (prefs); } @Override protected void onStartLoading() { if (prefs != null) { deliverResult(prefs); } if (takeContentChanged() || prefs == null) { forceLoad(); } } @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { Log.v(TAG, "wol: on shared preference changed."); onContentChanged(); } }
Here's how the bootloader is used:
public class MainActivity extends ActionBarActivity implements LoaderManager.LoaderCallbacks<SharedPreferences> { private static final String TAG = MainActivity.class.getSimpleName(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getSupportLoaderManager().initLoader(0, null, this);
Update I found this in the LoaderManager source. It looks like the onLoadFinished call onLoadFinished not called if the data has the same reference.
android commonsware-cwac android-support-library android-loader
Sababado
source share