- creating a fragment
demo - #1
MainFragment.kt
class MainFragment:Fragment(R.layout.fragment_main){
override onViewCreated(view: View,savedInstancestate:Bundle?){
super.onViewCreated(view,savedInstanceState)
}
}
fragment_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.constraintlayout.widget.ConstraintLayout>
activity_main.xml
<...ConstraintLayout
..
>
<fragment
android:name = ".MainFragment"
..
/>
</..ConstraintLayout>
Fragment is Created
----------Created-----------
- Fragment is added
- onAttach()
- onCreate()
- onCreateView()
- onActivityCreated()
----------Started-----------
- onStart()
----------Resumed-----------
- onResume()
Fragment is active
----------Paused-----------
- onPause()
----------Stopped-----------
- onStop()
----------Destroyed-----------
- onDestroyView()
- onDestroy()
- onDetach()
Fragment is destroyed