androidandroid-activityandroid-alertdialogandroid-immersive

Displaying a AlertDialog on screen irrespective of Activity Screen


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.

Here's what i am doing.

  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.

Thanks in advance.


Solution

  • 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.

    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