13
What are the differences in functioning, performance etc. in inheriting from each of the classes in controllers views (XML) on Android?
13
What are the differences in functioning, performance etc. in inheriting from each of the classes in controllers views (XML) on Android?
9
Both the Activity like the Fragment are components that provide a graphical interface (UI), to allow the user to interact with the application.
The fundamental difference is that a Fragment needs an Activity to be presented.
Fragment was introduced in Android 3.0 (Level 11 API) and its main purpose is to allow greater flexibility in creating UI adaptable to the various screen dimensions existing on current devices.
It allows centralizing the code referring to a part(fragment) of the UI.
When dividing the layout of an Activity into fragments, it is possible to modify the appearance of the Activity, at runtime, in a simple way.
Another advantage is the reuse of the code, as they can be used in more than one Activity.
Some people use Fragment without a view associated to implement the MVP standard.
The Ragment makes of presenter, taking advantage of the possibility that this has, calling the method setRetainInstance(true), not be destroyed during the recreation of the Activity (as resulting from the rotation of the device), maintaining the application status.
To Fragmentactivity is a "wrapper" around an Activity to allow Fragment to be used on Android devices prior to version 3.
5
I was going to reply through a comment because my knowledge in this aspect is limited, but it would get very large.
The difference, if any, is between Activities
and Fragments
. Performance I believe there is not. As for functionality, Fragments
, as they are reusable, they allow more complex interfaces than Activities
with simpler code.
As far as my little experience with MVP/MVC for Android goes, both Activities
as Fragments
require attention due to their life cycles. At the moment I cannot visualize whether the use of Fragments
makes communication between components more complicated, but I believe that minimizing this complication is one of the intentions of using MVP/MVC.
As for the other classes (FragmentActivity
, ActionBarActivity
, AppCompatActivity
), they exist for compatibility with older versions of Android. This answer in Soen illustrates the differences between them.
PS: If you’re talking about MVVM using Data Binding, then I don’t know anything. :)
Browser other questions tagged android android-fragment
You are not signed in. Login or sign up in order to post.
I forgot about this "detail" which is to explain the relationship/difference between activities and Fragments. Great explanation. :)
– Piovezan
@Piovezan For those who say they know little about the subject, their answer is good and received my +1.
– ramaral