开发者

The AlertDialog is invisible when the Activity back to foreground

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.


Indeed the dialog already shown but not visible to the user and it would become visible if you rotate the device.

There seemed a refresh/drawing issue if dismiss a progress dialog and show another new dialog immediately when the activity is not in foreground. During my testing, such issue not happen if wait for the dismiss action finished for the progress dialog and then show the new dialog.

So one solution is that show the AlertDialog first and then dismiss the ProgressDialog. That worked for my application.


I think, there is some king of bug in Dialog. I have the same situation, and only solution was dismiss curent dialog by dialogDismiss(id) and show it again by showDialog(id).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜