codepath / codepath/android_guides
Slight modification needed in Creating and Using Fragments guide
- Dominant language
- No language data
- Stars
- 28.3k
- Forks
- 6.2k
- PR merge metrics
- No merged PRs in 30d
Description
The **Creating and Using Fragments guide** needs slight modification in [this section](https://guides.codepath.com/android/Creating-and-Using-Fragments#fragment-hiding-vs-replace). **Fragment Hiding vs Replace** section states that
> we call transaction.replace(...) to load a dynamic fragment which first removes the existing fragment from the activity **invoking onStop and onDestroy** for that fragment before adding the new fragment to the container.
This official android [guide](https://developer.android.com/guide/components/fragments.html#Lifecycle) clearly states that fragment is killed when the parent activity is itself killed.
>Stopped
The fragment is not visible. Either the host activity has been stopped or the fragment has been removed from the activity but added to the back stack. A stopped fragment is still alive (all state and member information is retained by the system). However, it is no longer visible to the user and will be killed if the activity is killed.
Actually onPause(), onStop() and onDestroyView() are called after a fragment has been removed/replaced in a fragment transaction.
You can refer the [onDestroyView() explanation](https://developer.android.com/reference/android/app/Fragment.html#onDestroyView()) and see the [fragment life cycle diagram](https://developer.android.com/images/fragment_lifecycle.png) for confirming the above statement.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.