0

I have a question regarding the Network operation in android application, If suppose I have a async task in my application which is downloading data from Server via REST APIs.

My questions are

  1. While the async task is being executed if the user presses the home button what happens to the network operation?
  2. If I again start the application do i need to execute the network operation again?
user2622786
  • 779
  • 3
  • 9
  • 21
  • I feel you need to read http://stackoverflow.com/questions/16204693/asynctask-will-always-run-even-if-app-is-destroyed for your First question. – Sanket Patel Mar 10 '14 at 20:47
  • 1
    @SharpDeveloper was just going to post that link I have answered. Cheers. – wtsang02 Mar 10 '14 at 20:48
  • And for second question. If you have store your response in doInBackground() method of AsyncTask then you do not need to call again. Just Check that, Is response is not null or blank? if it is not means your call executed and you have data , so no need to download. Just simple logic you need to put there. – Sanket Patel Mar 10 '14 at 20:49

1 Answers1

0

No, you don't have to execute the network operation again, but you have to handle correctly the activity lifecycle (because this is not automatically the case with AsyncTask).

I suggest you to read this paper : http://www.vogella.com/tutorials/AndroidBackgroundProcessing/article.html#concurrency_asynchtask3

shemsu
  • 1,066
  • 9
  • 17