How to add fragment on activity in android? [duplicate]

You cannot switch from an Activity to Fragment, because a Fragment does not have its own existence without an Activity. i.e. a Fragment works inside an Activity.
Basically, Fragments are mainly used to create multi-pane screens.

Inside an Activity if you can replace Fragments (associated with the Activity) as mentioned in the above code examples to change the UI.

Leave a Comment