0

I am working on an android app and I have an async task in one activity and I want to use that async task into another activity. Can I do so?

user3713665
  • 147
  • 1
  • 7
  • 2
    You can move async task to new class and listen to it using [interface](http://docs.oracle.com/javase/tutorial/java/concepts/interface.html), so you can use in all the classes. – VenomVendor Jun 15 '14 at 12:06

3 Answers3

2

I think AsyncTask do use for in his class.Beacause This class allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers. AsyncTask must be subclassed to be used. The subclass will override at least one method (doInBackground(Params...)), and most often will override a second one (onPostExecute(Result).)

http://developer.android.com/reference/android/os/AsyncTask.html

0

I don't think it is possible at all. The one idea that came to my mind is to use Services and do an AsyncTask in it. The service has to be bound.

sebap123
  • 2,541
  • 6
  • 45
  • 81
0

Yes you can .create a new asynctask class with your common operation. And you can create callback interface and your activity must implement interface to get appropriate callback of asynctask.

Android, can I put AsyncTask in a separate class and have a callback?

Community
  • 1
  • 1
mcd
  • 1,434
  • 15
  • 31
  • Interesting answer. May test this when I get a chance and if it works I think it's the solution. – zgc7009 Jun 15 '14 at 12:44