I write a program support download file. When in this download activity, I start a progress bar and then run a thread to do the download things. This thread send message to UI thread to notify how many has been downloaded frequently. In the main(UI) thread, I update the progress bar display when receive the message. If any problem happen in download progress, it will send another message. When main thread receive the message, it stop the progress bar and pop up a new AlertDialog to show the error reason.
Here is a special test for it. When downloading, switch the program to settings. Turn off the WIFI/GPRS to make the network off.
When I back to my program, it should display the background ui and a pop up AlertDialog to show the reason as I wish. But it only display the background ui(which means the main activity) and with a half-light of backlight just as the popup windows still there. When I press back for first time, nothing happens except the backlight is bright just like I have close a pop up window.
I think maybe it is because when I start the AlertDialog my activity is not in foreground.
I tried to use:
ActivityManager am = (ActivityManager)Update.this.getSystemService(Context.ACTIVITY_SERVICE);
ComponentName cn = am.getRunningTasks(1).get(0).topActivity;
to judge whether the top activity is mine. But I want to show the dialog. If the activity isn't being seen by the user, when he gets back to my activity, I want it to show the dialog.