Android: Custom Dialog displays on back navigation - android

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?

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.

Android Dialog out of dialog click

I made a custom dialog (extends Dialog) and then make the object in Activity Sample.class
Then if I click one button in the Activity and the custom dialog shows up.
Here, the problem is, since the custom dialog contains the EditText, the soft keyboard is needed and it shows up, but if I click(tab) the screen outside of the dialog, the "cancel" listener is called so that the dialog is disappeared. However, what I want to implement is when I click the screen outside of the dialog, only just keyboard disappearing. Can anyone help me?
Use setCanceledOnTouchOutside(false) on the dialog instance. This will stop dismissing the dialog. But I am not sure the soft keypad will go away with this.
use this,
dialog.setCanceledOnTouchOutside(false);

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.

Cancel Dialogfragment click outside

I have a dialogfragment, which should dismiss, if i click outside of the dialog. I have no button or something else to close the dialog.
But before the dismiss is calling, I want to check a field in my dialog. If the check is positive, then the dialog should close, else not.
Which method can I override to do that? Or can I do it manual with a onTouchListener, which dismiss the dialog, if I'm clicking beside?
I would do following. I would add transparent button on background of your dialog fragment in order to fragment take all place and set onClickListener for that button. Maybe it's wierd but it's work ))

Categories

Resources