A Fragment represents some behaviors in the Activity or some user interfaces. You can combine multiple Fragment in an Activity to create multiple UI panels. You can also reuse one Fragment in multiple activities. You can understand Fragment as a module of Activity. It has its own lifecycle, accepts its own input events, and you can add and delete Fragment when the Activity is running.
A Fragment must be embedded in an Activity and its lifecycle is directly affected by the lifecycle of its host Activity. For example, when the host Activity is paused, all Fragment in the Activity will be paused. The same is true when the host Activity is destroyed. However, when an Activity is running (in the resumed life state), you can operate on each Fragment separately, for example, adding or deleting an Activity. When you execute such a Fragment transaction, you can also add it to a back stack managed by Activity, A rollback stack entry in the Activity is a Fragment transaction record. This rollback stack allows you to roll Back a previous Fragment transaction by pressing the Back key.
When you add a Fragment as part of an Activity, it is active in the ViewGroup in the internal view hierarchy of the Activity and has its own layout. You can add a fragment to the Activity through xml and java code.
From thick and thin hair, water comes to the fore