Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fragment vs. FragmentActivity [duplicate]

I am new in Android programming. I want to do a Fragment, I have seen examples that uses Fragment and FragmentActivity, What's the difference between them and which cases should be used each one? Thanks

like image 579
Fran Avatar asked Dec 11 '22 16:12

Fran


2 Answers

FragmentActivity is our classic Activity with fragment support, nothing more. Therefore FragmentActivity is needed, when a Fragment will be attached to Activity.

Well Fragment is good component that copy the basic behaviors of Activity, still not a stand-alone application component like Activity and needs to be attached to Activity in order to work.

Read here Difference between Fragment And FragmentActivity

like image 191
Marko Niciforovic Avatar answered Dec 21 '22 11:12

Marko Niciforovic


FragmentActivity is part of the google-support-v4 lib which is basically adds a Fragment support to system with OS under 2.3. So FragmentActivity is exactly as a simple Activity only it gives you the ability to add Fragment to it.

Fragment is an object that shares parts of the Activity life cycle and can be added as part of you UI to an Activity or FragmentActivity with it's logic. the beauty of Fragments is that can be reused across different Activities in your application.

like image 32
Emil Adz Avatar answered Dec 21 '22 11:12

Emil Adz