0

I'm building a small test app that interacts with some basic php scripts on my server.

Essentially I have three activities that each download the same information which I parse in slightly different way for each.

At the moment I have simply copied the async task function to each of the activities.

I'm sure this is a needless replication and that their must be a way to share this function between each of the activities.

Is it possible for me to hold the async task in a separate class and call it from each?

Eg. I can call "async task class" from Activity A,B or C, it starts on a background thread then returns the unparsed results to the ui thread when its done?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
user2014175
  • 169
  • 2
  • 4
  • 10
  • Thanks for this codeMagic, but I still cant work out how I am supposed to 1) Notify the main thread that the operation is complete and 2) retrieve the result from the download on the main thread? – user2014175 Aug 15 '14 at 14:59
  • That answer shows you how to implement an `interface` into any `Activity` which calls the `AsyncTask` that is in it's own file. Give it a try. You just implement the callback method in your activity and send the response through `onPostExecute()` – codeMagic Aug 15 '14 at 15:04
  • Ah got you, thanks, hadn't read far enough down. Thanks again – user2014175 Aug 15 '14 at 15:09
  • No problem. Go through that and if you can't get it working then you can post a new question with detailed information on where you are stuck. It sounds like you have a basic understanding of `AsyncTasks` but if not [this answer might help also](http://stackoverflow.com/questions/18898039/using-asynctask/18898105#18898105) – codeMagic Aug 15 '14 at 15:15
  • 1
    Yeh, the first one you posted got me there perfectly. Shouldn't have replied without reading till the end. Apologies. Thanks again. – user2014175 Aug 15 '14 at 16:09

0 Answers0