views:

619

answers:

2

In my activity there's some stuff going on in a background thread, which gets started in Activity_1. The processing of the background thread takes a while and I want to notify the user when it's completed via an AlertDialog. However, the user might have changed to Activity_2 or Activity_3 in the meantime and I would like to pop up the AlertDialog always in the current Activity.

Any idea how to realize this?

A: 

This probably means the right way is to use a Service, instead of a plain background thread. Your background work will be more resilient to being paused or shut down, and you don't have to worry about making an AsyncTask that is constantly keeping track of a different Activity parent.

Klondike
My "background thread" is actually a separate service. What I'm looking for, though, is a application global message (Dialog) that can be raised anywhere in the application. Does that mean I have to implement a Listener and a Dialog in every activity or can I do that at one single point for the whole application. The other question is, what am I listening for (is it an Intent or something else)?
znq
+1  A: 

I ended up doing something like this in my background thread. It works, but not sure if it is a "good" solution.

Looper.prepare();
mActivity.showDialogAlertDefault();
Looper.loop();
Looper.myLooper().quit();
znq