Ivan the Russian
Ivan the Russian

Reputation: 110

Same asynctask but different result handling in onPostExecute()

Currently I have an AsyncTask declared both in my main activity class and in my widget class. The code is the same except for the result handling in onPostExecute (in activity the result retrieved goes to a textview within activity and in the widget it goes to a textview in my widget).

I'd like to move the AsyncTask to an external java file (to avoid code duplication) and somehow call it from other different classes (like my widget and main activity) with different result handling. I guess I can't just pass a method name as a parameter to call it from onPostExecute, but is there something else I can do?

Upvotes: 1

Views: 62

Answers (1)

Yash Sampat
Yash Sampat

Reputation: 30611

The short answer to your question is NO, you cannot do anything about this. In general, AsyncTasks are Activity-specific, and are defined as inner classes inside different Activitys so that they have access to methods defined in that Activity.

You can go ahead and define the same AsyncTask inside the Activity and the widget.

Upvotes: 1

Related Questions