Getting Reference to Calling Activity from AsyncTask (NOT as an inner class)

Posted by stormin986 on Stack Overflow See other posts from Stack Overflow or by stormin986
Published on 2010-04-27T07:29:11Z Indexed on 2010/04/27 7:33 UTC
Read the original article Hit count: 146

Filed under:
|
|

Is it at all possible, from within an AsyncTask that is NOT an inner class of the calling Activity class, to get a reference to the instance of Activity that initiated execution of the AsyncTask?

I am aware of this thread, however it doesn't exactly address how to reference the calling Activity. Some suggest passing a reference to the Activity as a parameter to the AsyncTask constructor, however, it's reported that doing so will always result in a NullPointerException.

So, I'm at a loss. My AsyncTask provides robust functionality, and I don't want to have to duplicate it as an inner class in every Activity that wants to use it. There must be an elegant solution.

© Stack Overflow or respective owner

Related posts about android

Related posts about asynctask