Can We Use Fragment Without Activity in Android?
Contents

Fragment can’t be initiated without Activity or FragmentActivity. As soon as you create an instance of the Fragment class, it exists, but in order for it to appear on the UI, you must attach that fragment to an activity because a fragment’s lifecycle runs parallel to an activity’s lifecycle.

Can we use fragment instead of activity?

Fragment cannot be used without an Activity. While Using fragments in the project, the project structure will be good and we can handle it easily. Lifecycle methods are hosted by OS. The activity has its own life cycle.

Is a fragment an activity android?

A Fragment is not an Activity. Fragments are hosted inside a FragmentActivity. Check PJL’s answer for more information. In Android an Activity can contain several Fragments inside.

Sophia Al-Mansoor

Sophia Al-Mansoor

Global Business & E-Commerce Reporter

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.

Share this article
Twitter Facebook Pinterest