4

I have a class (like a helper class) -not an activity- which manages soap requests. I use this class to send soap requests that comes from activities by method doInBAckground and catch all return values from webservice by onpostexecute. Everything is ok but my problem starts at this point because I could not pass return value asynctask class to main class.

Mustafa Güven
  • 15,526
  • 11
  • 63
  • 83
  • 2
    Have a look at this [Answer](http://stackoverflow.com/questions/7618614/return-data-from-asynctask-class/7618705#7618705) – Adil Soomro Oct 07 '11 at 09:39
  • just use the context of the activity and using that context set the value to the data member of activity. – user370305 Oct 07 '11 at 09:43
  • @AdilSoomro Thank you. Here is the latest and runnable code. http://aaarkonusurum.blogspot.com/2011/10/asynctask-classtan-donen-parametreyi.html – Mustafa Güven Oct 07 '11 at 11:54

2 Answers2

1

You can have some utility class available as singleton (ok, singleton is dangerous pattern but it use is justified in android until we get sane and usabel dependency injection ) and pass result there.

Advandatges: - no messing with intents / serialisability - pass data or call some methid or do whatever you like - all your activities share the same instance of singleton service.

Disadvantages: - singleton pattern is considered dangerous

You may even go further and make your service singleton - you will start methods of it as async tasks, and then your activity may query results over dedicated methods.

Or you may go a step further - register your activity as listener in async service, and call method in this activity when ready (note: as this will be not a UI thread, you will be unable to do something with UI unless you use runOnUiThread()

Konstantin Pribluda
  • 12,329
  • 1
  • 30
  • 35
1

Have you tried implementing the AsyncTask as an inner class of your Activity?

Thommy
  • 5,070
  • 2
  • 28
  • 51