slezadav
slezadav

Reputation: 6141

Changing context during AsyncTask

I have a service which runs for quite a while and collects data. At the end, it starts an AsyncTask and is finished. The catch is that in AsyncTask's onPostExecute() I want to show a Toast, but I don't have a correct context, because by the time AsyncTask finishes, the service doesn't exist anymore. So how can I pass some other context to the service for this toast to show ? Even better would be showing the toast independently of where in the application the user is, because in worst-case scenario the AsyncTask may finish after quite a long time and user may have navigated elsewhere in the mean time. In case this is not possible, what options do I have for informing user about AsyncTask's success ?

Upvotes: 1

Views: 133

Answers (1)

Evos
Evos

Reputation: 3915

According to discussion under the main question, the best solution in your case would be to not stop your Service until all AsyncTasks (started from this service) will finish their work.

Upvotes: 1

Related Questions