Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is lifecycle of DialogFragment

Tags:

I could not find proper lifecycle of android.support.v4.app.DialogFragment by searching on Google. I need this for some implementation. As we know DialogFragment has some methods same like Dialog.

DialogFragment extends Fragment so its lifecycle is same as Fragment. But what about other methods of DialogFragment?

Here is Fragment lifecycle. Can one provide for DialogFragment?

enter image description here

like image 459
Khemraj Sharma Avatar asked Jul 31 '18 13:07

Khemraj Sharma


People also ask

What is DialogFragment?

Android DialogFragments. DialogFragment is a utility class which extends the Fragment class. It is a part of the v4 support library and is used to display an overlay modal window within an activity that floats on top of the rest of the content. Essentially a DialogFragment displays a Dialog but inside a Fragment.

What is fragment and its lifecycle?

Each Fragment instance has its own lifecycle. When a user navigates and interacts with your app, your fragments transition through various states in their lifecycle as they are added, removed, and enter or exit the screen.

How do you finish DialogFragment?

Show activity on this post. tl;dr: The correct way to close a DialogFragment is to use dismiss() directly on the DialogFragment. Control of the dialog (deciding when to show, hide, dismiss it) should be done through the API here, not with direct calls on the dialog.

Is DialogFragment deprecated?

This class was deprecated in API level 28. Use the Support Library DialogFragment for consistent behavior across all devices and access to Lifecycle.


1 Answers

DialogFragment life cycle is similar to the life cycle of fragment:. To test yourself put logs in each of the overrided methods of dialogFragment and then run your code you will understand the working of dialogFragment.

onAttach onCreate onCreateDialog onCreateView onActivityCreated onStart onResume 

And as far as finishing or destroying dialogFragment is concerned the lifeCycle is as follows:

onPause onStop onDestroyView onDestroy onDetach 

Also I believe this method will also help you know the lifecycle :

@NonNull @Override public Lifecycle getLifecycle() {     return super.getLifecycle(); } 
like image 172
Umair Avatar answered Oct 10 '22 04:10

Umair