Android: raise AlertDialog from background theme

In my activity, some things happen in the background thread that starts in Activity_1. Processing the background thread takes some time, and I want to notify the user when he is done using AlertDialog . However, the user can be changed to Activity_2 or Activity_3 in the meantime, and I would like to pop up AlertDialog always in the current Activity.

Any idea how to implement this?

+7
android multithreading background dialog
source share
2 answers

I ended up doing something similar in my background thread. It works, but not sure if this is a “good” solution.

 Looper.prepare(); mActivity.showDialogAlertDefault(); Looper.loop(); Looper.myLooper().quit(); 
+3
source share

This probably means that the correct way is to use the Service instead of a simple background thread. Your background jobs will be more resilient to pausing or shutting down, and you don’t have to worry about making AsyncTask, which is constantly monitoring another activity parent.

0
source share

All Articles