I have an AsyncTaskLoader that loads and processes a large amount of information. When I turn off the application, I need to stop it (... until he ate all my traffic). When the process is murdered, it does not stop (although what I was hoping for :)). In onDestroy I tried to write this:

 Loader loader = getSupportLoaderManager().getLoader(LOADER_ID); if (loader != null) { ((AsyncTaskLoader) loader).cancelLoadInBackground(); getSupportLoaderManager().destroyLoader(LOADER_ID); } 

But he continued loading in the background. How to stop it?

  • Something Google is silent about this ... Maybe you are nailing him after super.onDestroy() ? .. Well, in the docks something else about onLoaderReset(Loader) is written - they say it will be called if the loader has already given something to of destruction ... - YuriySPb
  • I have an empty onLoaderReset method, I have not used it. But he is not beaten - logs go and go ... - user189127
  • Well ... And if he’ts a dirty hack to kill a process tightly: Process.killProcess(Process.myPid()); ? .. - YuriySPb
  • @ bukashka101 And in what method did you call the initLoader method? - BORSHEVIK
  • @BORSHEVIK, in the usual private method that is called in onClick . - user189127

1 answer 1

Call AsyncTaskLoader.cancelLoadInBackground() .

http://developer.android.com/intl/ru/reference/android/support/v4/content/AsyncTaskLoader.html#cancelLoadInBackground ()

  • And where to call cancel(true) ? Neither Loader'a nor Loader'a has such a method. - user189127
  • @ bukashka101 see update - Daniel Shatz
  • I tried, but it did not help. Download continues. - user189127