DialogFragment without animation - android

I have DialogFragment with slide up animation on show. After clicking a button in dialog I start another activity without dismissing my dialog. The problem is, every time I finish an acitivity, the animation runs on dialog. Is there any way to turn off dialog animation after dialog is shown?

The situation sounds weird: if it's a DialogFragment that is attached to the first Activity, then how is it that you would keep the dialog showing when you start a different Activity? Or are you just re-starting the DialogFragment for both of your Activities?
Anyway, without knowing more details, there are a couple of things you can try.
If it really is the same DialogFragment instance that is running the same animation twice, then you can add a boolean in the dialog that is initially false, and gets set to true when you fire the animation. Then only fire the animation when the boolean is false.
If you are starting the same DialogFragment twice, for each of the two Activities you describe, then you can use setArguments(Bundle) right after constructing the DialogFragment, and add a boolean argument that says whether you want to show the animation.

Related

DialogFragment reappears after activity recreate() even after dismissing it

I am showing one DialogFragment inside an activity. Now when I call recreate from the activity (trying to reproduce kill on low memory issue) I want to dismiss the dialog. So I tried calling dismissAllowingStateLoss() and removing fragment from the onStop of the fragment. But even after that I see onCreateDialog() of DialogFragment getting called.
My objective is to cancel the dissmiss the DialogFragment when acitvity recreates, but for me dialog is always reappearing, Can anyone help me on this issue?
The proper way to do it is to do it from parent activity but it looks like in your case parent activity have no control on you dialog fragment, right?
So your DialogFragment is more like a "Toast" dialog with a timer or with an OK button, correct?

How to dismiss DialogFragment from AsyncTask, when the home button is pressed and the device is resumed with changed rotation

I have an AsyncTask which dismisses the DialogFragment. I am facing a problem when the AsyncTask tries to dismiss the dialog after pressing the home button. dismissAllowingStateloss() helps to this case, but one issue still remains. When I press home button and then rotate, the AsyncTask tries to dismiss the activity, but as the orientation is changed, the activity calls onDestroy() and recreates the stuff. As a result the DialogFragment is on the screen again. setRetainInstance is set to true for the DialogFragment. The normal dismiss() raises IllegalStateException by saying do not call after onSavedInstance().
Any idea how to fix this by keeping the DialogFragment independent from the Activity? I mean without putting tracking variables in the Activity. I do not want to do this, because I do not want to write that stuff for each Activity where I would use this dialog.

Re-display parent dialog after child dialog closes

In my app, I display a custom Dialog (using DialogFragment), which on certain action causes another custom Dialog to be shown (using another DialogFragment). This all works fine. However when the "child" dialog is closed, I want to return to the parent dialog (which is closed/hidden when the child is displayed).
I do not want just display another instance of the same dialog, as I need to maintain states and behaviours of the parent prior to the child being open. Therefore I need to re-display physically the same dialog.
I can't seem to find a way of doing so.
Coming back to it as I now got a solution that seems to work. Apparently, using dialog directly will close the previous dialog when a new one is opened. Yet, when using DialogFragment, the previous fragment stays on screen when the new fragment is displayed. Then when the dialog on the new fragment is closed the previous fragment is still visible - exactly what I need.

Dialog with outside touchable

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.

Android: Dismissing a dialog before displaying another

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.

Categories

Resources