开发者

Android: The AlertDialog is invisible when the Activity back to foreground

This question is related to The AlertDialog is invisible when the Activity back to foreground post.

I have the same problem. The previous post is old, and have no开发者_开发知识库 answer. Any suggestions how to solve that problem ? Thanks...


For some reason, Dialogs' states must be handled by the developer.

Simply keep a reference to the dialog showing

For example

Dialog showingDialog=null;

Now in onResume()

if(showingdialog!=null)
    //show the dialog and maybe resume some state


Have you tried to re-display the AlertDialog when in the activities onResume(). Using Google developers example you would be able to create an instance of this dialog and just recall it.

http://developer.android.com/guide/topics/ui/dialogs.html#AlertDialog

Hope that helps.


Also we all create Dialogs on the fly whenever we need them, we should not.

Android way is (by the book) to override an onCreateDialog(int) and showDialog(int) in our activities so that our dialogs can be managed by the activity lifecycle.

Another way to do so is to use myDialog.setOwnerActivity(MyActivity.this) to tell the dialog it is managed by the activity.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜