views:

28

answers:

1

An activity I have starts an AsyncTask. What is the best way of getting the Activity notified that the AsyncTask is done. I can pass the Activity as a Context in, but I don't want the AsyncTask to know about the type of the Activity.

In .NET land I would subscribe to an event on the "AsyncTask". I didn't find a way to do that in Android.

A: 

One way is to send a broadcast when the AsyncTask finished, and if you have different types of activities the one that is active will receive it. In order to send a broadcast you have to pass a context to the AsyncTask, but your AsyncTask doesn't need to make a difference what context is that.

Pentium10