Work with DIalogs in fragments

In my application, I have an Activity and some fragments (Activity works like a Controller and Fragments - like views)

In some fragments I need to show AlertDialogs and ProgressDialogs, Activity can change the current fragment.

My problem: an activity can receive broadcast messages and C2DM notifications, and when I created AlertDialog, an Activity can change a fragment, but Dialog remains. Therefore, when the user clicks on some buttons, the application crashes.

DIalogFragments works like a simple dialog.

Disable the dialog manually or check if the fragment is active? Are there any built-in tools?

+4
source share
1 answer

First of all, I could have missed something, without code, etc., but ...

Secondly: maybe you should not use dialogs? This seems to be a cumbersome user interface. Just use snippets for them? Although you say that you are using DialogFragments, you may already have thought of this and are using them as β€œregular” fragments already.

Third: Reject dialogs when the fragment that showed was deleted / hidden? Use the onStop () callback, for example, in a fragment or in a more central place where you might save the currently displayed fragment and decide to display a new one. Disable the dialog by calling wismiss in the Dialog object or Fragment or dismissDialog in the Activity.

See the rejection dialog: http://developer.android.com/guide/topics/ui/dialogs.html#DismissingADialog

You can still decline these dialog boxes. http://developer.android.com/reference/android/app/DialogFragment.htm

+1
source

Source: https://habr.com/ru/post/1400985/


All Articles