What is the difference between include a layout or include a fragment in Android?
From the Android docs:
A Fragment represents a behavior or a portion of user interface in an Activity. You can combine multiple fragments in a single activity to build a multi-pane UI and reuse a fragment in multiple activities. You can think of a fragment as a modular section of an activity, which has its own lifecycle, receives its own input events, and which you can add or remove while the activity is running (sort of like a "sub activity" that you can reuse in different activities).
The important part of this is that Fragments
have their own lifecycle. This means you can start, pause, resume, stop, etc. a Fragment
. You can't do any of that with a layout. It's also wise to note that Fragments
contain their own layouts.