The normal way to create an alert dialog is to attach it to the current activity, like in How do I display an alert dialog on Android?
However, what I want to achieve is to create an alert dialog that is not attached to a particular activity. So that when the activity is destroyed (e.g. using finishAndRemoveTask), my dialog is still here.
Is there a way to achieve that? Also, I would like the area outside of the alert dialog to be unclickable, i.e. the user must click on the ok button of the dialog in order to navigate to other activities.
Related
Since I read showing Alert Dialog on Service may damage on other program , I want to know is there difference between showing Alert Dialog directly like this:
AlertDialog alertDialog = builder.create();
alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
alertDialog.show();
And showing through specific activity?
I want something like communication application's popup (e.g. Line Messenger,..)
which of ways do you recommend?
You can start a Transparent activity from your service which shows the dialog within itself.
First create the "transparent" activity and set its theme like this in the Manifest
<activity android:name=".MyPopUpActivity" android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen"/>
Set the background of this activity to a transparent colour of your choice.
From your service, start this activity. Make sure to pass whatever data needed to show the Dialog.
Once the activity is launched, use a DialogFragment to show the dialog. Using DialogFragment is the recommended way to display dialogs in android.
I haven't tested this approach myself but I am pretty sure it will do the trick for you.
Let me know if it works for you
I have two alert dialogs. Whenever app opens, the first dialog is shown. After some time, the second dialog is shown. But here problem is recently created dialog(second one) is in front. But I want the fist created dialog is in front and second one is behind the first one.
The problem with the dialog box is that you can not display two dialog box at a same time. You must hide first dialog box in order to display second one.
You can only display one dialog at the time, but you can "work around" this. When you are about to display your second dialog, you hide your first dialog, but your application remembers that the first dialog was open, so when you hide your second dialog you displays the first dialog again. In reality this will go so fast so the user is fooled that the dialog is layered over eachother(if they have the same dimensions).
But you cannot display a dialog on top of another dialog.
You can display first dialog in front :
When you are calling to display second one at that time call first dialog again so, that is in from view of your screen.
Let me know you understand this or not.. otherwise i will provide code for it..
You cant make two dialog active at same time either one should active and the other should inactive.In your case if you want the second should come background of fist then you have to call first dialog from the second.
I want to create a pop up window from my dialog with out closing dialog.
While I create pop up window from dialog.The pop up window comes under the dialog and can't see that.Is there a way for create a popup window over dialog box.
The only thing I can think of is starting an activity as a dialog like here and in that activity you should be able to start a normal dialog.
You can call/create another alert dialog inside this dialog and this will appear above the current one
I have an Activity, and inside that activity, i have several dialogs popup at unknown times. I would like the user to still be able to interact with the current activity (Press Buttons etc) whilst the dialog is being displayed. Is this possible or would there be an alternative solution to this? I have setup my dialog like so, to prevent it from closing on outside touch:
achievDialog = new Dialog(this);
achievDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
achievDialog.setContentView(R.layout.achiev_get);
achievDialog.setCanceledOnTouchOutside(false);
In an android application, I want to display a Dialog on screen and in the same time to allow user to click on the application's UI when the the Dialog is open
can this be done?
if no, what can I use instead of Dialog?
I don't think you can do this with Dialog. But you can do it with PopupWindow using PopupWindow.setOutsideTouchable(true);.
Showing up a dialog over your Activity, will make your Activity go into onPause() so you won't be able to actually handle things inside that activity anymore until the dialog is dismissed.
If you want to have some view, overlay your original activities view you'll be looking for into the direction of FrameViews, which can overlap other Views.