与活动屏幕无关,在屏幕上显示AlertDialog [英] Displaying a AlertDialog on screen irrespective of Activity Screen

查看:144
本文介绍了与活动屏幕无关,在屏幕上显示AlertDialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论用户位于什么屏幕,我都希望显示一个对话框.假设用户打开应用程序,并且在初始屏幕中,如果收到服务器消息,则必须在对话框中显示它.同时,有一个autologin选项.因此它可以转到我的下一个活动.如果是这种情况,则不应该关闭对话框.它应该显示在新打开的活动上而不是上一个活动上.另外,即使显示了对话框,我也应该能够控制我在活动上的按钮.

I want to show an Dialog Whatever the screen the User is in. Suppose if user opens application and in initial screen if I receive a server message I have to show it in a dialog.Meanwhile there is an option of autologin . So it could move to my next activity.If this is the case that dialog should not be closed.It should show on newly opened activity rather than the previous activity.And other thing is that even though the dialog is shown I should be able to control my buttons on the activity.

这就是我在做什么.

  if(Activity1.mcontext!=null){
                                    CommonMethods.showDialog(sliderMessageText, 

                                    LoginActivity.mcontext,"activity1");
                                }
                                if(Activity2.context!=null){
                                    CommonMethods.showSliderMessageText(sliderMessageText, 

                                            Activity2.context,"activity2");
                                }
                                if(Activity3.mcontext!=null){
                                    CommonMethods.showSliderMessageText(sliderMessageText,Activity3.context,"activity3");
}

相反,我在所有活动中都显示对话框.

Instead I am displaying the dialog in all the activities.

谢谢.

推荐答案

您可能要考虑使用事件驱动的模型,例如GreenRobot.

You may want to consider using an Event driven model such as GreenRobot.

http://greenrobot.org/eventbus/

这将使您能够有效地处理您描述的情况.

This would allow you to efficiently handle the scenario you describe.

或者,您可以使用LocalBroadcastManager在应用程序的不同部分之间进行通信.

Alternatively, you can use the LocalBroadcastManager to communicate between different parts of your app.

例如,当您要显示对话框并在所有活动中处理该消息时,发送广播消息

e.g Send a broadcast message when you want to display a dialog and handle that message in all of your Activities

这篇关于与活动屏幕无关,在屏幕上显示AlertDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆