android - Getting Reference to Calling Activity from AsyncTask (NOT as an inner class) -
is @ possible, within asynctask not inner class of calling activity class, reference instance of activity initiated execution of asynctask?
i aware of this thread, doesn't address how reference calling activity. suggest passing reference activity parameter asynctask constructor, however, it's reported doing result in nullpointerexception.
so, i'm @ loss. asynctask provides robust functionality, , don't want have duplicate inner class in every activity wants use it. there must elegant solution.
the "elegant solution" try passing parameter (to constructor or execute()
) , see if works, rather assuming person asked previous question (then answered own question twice) knows doing. can think of nothing intrinsic asynctask
cause activity
bad constructor parameter , every other object fine.
now, haven't passed activity
(or other context
) parameter asynctask
, because asynctasks
private inner classes. in fact, fact want public asynctask
me code smell, suggesting these tasks should mediated service
or other control point. but, that's me.
update
a better answer handling pattern can found here: background task, progress dialog, orientation change - there 100% working solution?
Comments
Post a Comment