Is there a way to control the relative stacking of Dialogs produced by your own Activity? For instance, there are some more important Dialogs which I would like to ensure are on top and if another Dialog wants to pop up I would want it to pop under the important Dialogs.
Example: I want to present to the user an important dialog, Dialog A. The activity realizes that there is a dialog, Dialog B, of lesser importance to display to the user. Is it possible to specify Dialog B to be under Dialog A so that when Dialog A is cleared, Dialog B will be seen by the user?
I know that the onDismiss interface exists, but this necessarily ties Dialog A and Dialog B together. I want the Dialogs to be independent and would prefer to use a higher level abstraction like the window stack responsible for ordering the Dialogs.
There no such way as far as I know.
Related
Can a dialog on an android tablet manage its own back stack? In other words: Can you show multiple levels of navigation within a dialog?
On iPad, this is a very common design pattern: A sheet or popover with a navigation bar on top.
When I try this on android (using Fragments) I only have one FragmentManager: the one from the hosting FragmentActivity. I can push multiple dialog fragments on its back stack. The visual effect of such a push, is that one dialog (A) disappears and another one (B) appears. As the user taps 'back', B will disappear again, and A will re-appear again. That is usable, but I was hoping for a smoother transition that feels more like a single context.
A Dialog is a sub-window within an Activity so no, the framework doesn't manage back stacks for Dialogs automatically for you.
What you can do instead is use an activity and give it a dialog theme. This activity will look like a dialog (i.e. translucent background, etc.) but it will have all of the capabilities of a normal activity. See this link.
I want to show an Alert Dialog such that it stays on screen even if I go back to previous activity just after showing an alert dialog. Is is possible?
I tried using applicationContext but it does not work.
I don't think so, and I believe this would be a bad user experience. Perhaps you should re-think the design.
You cant do that , because a dialog is attached with a single window context , if window changes the dialog memory will be leaked and it will automatically close the dialog .You can make a same effect by showing the same dialog in both screens .However you will definitely see the transition of dialog with activity .
You can create an activity and give it a dialog theme. That way you dont have to worry about the context. It doesnt make a difference to the user also as it looks just like a dialog.
But I agree with AndyRes, It would be a bad user experience.
I have tabs that when tapped will show a view for each tab. Is it possible to create an AlertDialog that is specific to a particular view and only shows when the view is shown? So if the user taps on one tab, they would see an AlertDialog but if they tap on a different tab, the AlertDialog will not show. I don't believe its possible because I believe an AlertDialog is global within the app and when shown comes to the foreground making it impossible to tap on anything else until the dialog is dismissed. But maybe I'm wrong.
No, it is not. You may try to switch to Fragments and FragmentDialog as that would allow you to 'bind' dialog to a fragment, and each fragment can sit on separate 'tab' of your app (yet, you'd need to rework your app anyway). If you want to use 'traiditional' dialog, then you have to add a logic yourself, and not show it if different than expected tab is visible.
This seems like a pretty simple question, but I'm not sure if it's even possible. Is it possible to allow the MENU button to still bring up the option's menu when a dialog is showing on top? I want to do this because I want to give the user some more options while a dialog is opened.
I don't think that is possible.
Although the docs say that you should be able to do this.
A dialog is always created and displayed as a part of an Activity. You should normally create dialogs from within your Activity's onCreateDialog(int) callback method. When you use this callback, the Android system automatically manages the state of each dialog and hooks them to the Activity, effectively making it the "owner" of each dialog. As such, each dialog inherits certain properties from the Activity. For example, when a dialog is open, the Menu key reveals the options menu defined for the Activity and the volume keys modify the audio stream used by the Activity.
http://developer.android.com/guide/topics/ui/dialogs.html
My application displays alert dialogs in some cases. Also, it is possible for a user to launch my application using the VIEW/SEND intent. The scenario I am considering is, the dialog is visible, the user presses 'Home' & selects my application to View/Share a file.
I would want to dismiss the dialog before beginning with the view/share operation. Although I can maintain which dialog is visible and hide it before the operation begins, I was wondering if there is a conventional/recommended way or API, something like activity.dismissAnyVisibleDialog() that can come in handy.
Thanks a lot,
Akshay
I finally myself maintained which dialog is visible & dismissed it before displaying the next one.
-Akshay
Just close the dialog in the onPause() method (override in your activity).
This way it will be dismissed when the activity is no longer visible i.e if you switch to the home screen.