When is it better to use a Fragment over an Activity?
When is this useful?
Now you could do a list like below where each item in the list is associated with an ID which you send through an intent to another activity. This might look great on phone with a relatively small screen, but on a larger device like a tablet, as you can see below, it could definitely look better.
This is where fragments come to the rescue. Let's go back to that list. Now lets say that each item in that list actually has a reference to a JobSite object that has all of the information about the job site. The fragment can pass objects through the activity to another fragment within the same Activity. Doing that you can fairly easily do something like this.
On a mobile phone you can easily use an animation to slide, expand, fade or whatever animation works best for you. On a tablet however this makes your app more user friendly across a wider range of devices.
Passing data from the Fragment to the parent Activity is fairly simple. Within the fragment make a call to getActivity() and you can use all of the accessor methods available in the parent Activity.
On a mobile phone you can easily use an animation to slide, expand, fade or whatever animation works best for you. On a tablet however this makes your app more user friendly across a wider range of devices.
How do I pass information to the Activity?
Passing data from the Fragment to the parent Activity is fairly simple. Within the fragment make a call to getActivity() and you can use all of the accessor methods available in the parent Activity.
No comments:
Post a Comment