1

I have a problem understand Asynctaskloader... I seen examples override only the loadInBackground method and return the result. Also have seen examples which override onStartLoading, onReset etc ..

If i only override loadInBackground, will there be any problem, I mean if Activity quit, will the loadInBackground still continue to execute coz I can see the AsyncTask will.

LittleFunny
  • 8,155
  • 15
  • 87
  • 198

1 Answers1

0

For basic functionality, you only need to override loadInBackground.

If i only override loadInBackground, will there be any problem, I mean if Activity quit, will the loadInBackground still continue to execute coz I can see the AsyncTask will.

The AsyncTaskLoader will continue to load in background on Activity quit.

The only thing AsyncTaskLoader provides over AsyncTask is that, AsyncTaskLoader would know whether the task has been run / is running on Activity recreate, and attach to the existing task or recover the result without rerun the AsyncTask, e.g. on screen rotation. Given that you use LoaderManager.initLoader(), LoaderManager.resetLoader() correctly

Edit: The AsyncTaskLoader need a whole structure, i.e. AsyncTaskLoader, LoaderManager, LoaderManager.LoaderCallbacks

Derek Fung
  • 8,171
  • 1
  • 25
  • 28
  • Does that mean if I need to deal with whether the task need to rerun or not I have to do more than just overriding the loadInBackground. – LittleFunny Aug 29 '15 at 06:11
  • http://developer.android.com/reference/android/content/AsyncTaskLoader.html For AsyncTaskLoader you only need to override loadInBackground, but you should not create and use AsyncTaskLoader directly as a normal class. You have to follow the link above and use `LoaderManager` e.g. `getLoaderManager().initLoader(0, null, this);` and implement `LoaderManager.LoaderCallbacks`. SImply put, you need the whole structure. – Derek Fung Aug 29 '15 at 06:15