DialogFragment reappears after activity recreate() even after dismissing it - android

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?

Related

DialogFragment over DialogFragment produces spawn with no background animation

Good evening. A fast question.
i have seen that showing a not-fullscreen dialogfragment over activity or fragment, animates normally.
but when dialogfragment is showing over other dialogfragment, it animates the view BUT the dimmed background is not animating..its just appears.
Any reason why? also any workaround?
example:
Open a fullscreen dialogfragment and then open a non-fullscreen dialogfragment. You will notice that the "semitransparent" dim background is never animating.
If the fullscreen dialogfragment, were fragment(or activity), it would work fine

Android: Custom Dialog displays on back navigation

The application displays a custom dialog by using the code dialog.show(getActivity().getSupportFragmentManager(), TAG); with in a conditional statement from OnStart method of a fragment.
But the issue is, after dismissing the fragment and navigate to any other Activity and click on back button displays the custom dialog again even the conditional statement is false.
How to suppress the dialog from being displayed.
In your onStop and onPause dismiss the dialog by dialog.dismiss(). Make a global object of dialog.
The reason is that you dialog is never dismissed and it stays in your activity so when you come back it is shown.
Do you set your condition to false after dialog dismiss?

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.

DialogFragment without animation

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.

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