-2

Can anyone explain me the behavior of AsyncTask, is AsyncTask running when we press the back/home button or we switch from Activity A to Activity B.

Pankaj
  • 7,908
  • 6
  • 42
  • 65

2 Answers2

1

According to my knowlege Asynktask require userInterface if you close your activity by pressing onBack than load asynk task is not possible but if you call another activity On onBack press than as a result onCreate method of Any Activity Which is load By onBack press you can call AsynkTask.. and in your case suppoze you switch from "activity A" to "activity B" than onCreate method of activity B you can call AsynkTask as well as before starting "activity B" you can prepare data for "activity B" and as a result of Asynktask in onPostExecute method you can call "activity b" with data for "activity B".

Nitin
  • 79
  • 1
  • 10
0

Pressing the back button: Your asynctask's doInBackGround() will finish because it runs in a thread separate from the main UI thread; if for instance its task had been to upload a large file to a remote server it will complete that one. But since your activity has been destroyed it will never be able to deliver its results to onPostExecute();

Albert
  • 21
  • 5