A Bundle can easily store simple values such as strings, numbers, booleans. But to store a complex object, the object's class needs to implement an interface named Parcelable. The arguments you pass to a fragment are in the form of a bundle. Hand-coding a parcelable object is a bit difficult, but fortunately there are some useful open source tools that can make this easier. I'll describe on that's currently available online, and another that's designed to be installed into Android Studio as a plugin.
- [Instructor] I've previously shown how to send…a message from a fragment to an activity,…by using an interface that lets you pass values…through a call back method.…Some developers will prefer to take these values…and package them into data objects.…And to demonstrate this, I've already created…the data object in this project, named person dot java.…It has three fields for first name, last name, and age,…and all of the required setters and getters.…To make it a little bit easier to use this class,…I'll add a constructor method that receives the three values…and saves them persistently.…
I'll place the cursor here after…the three field declarations.…Then I'll go to the menu and choose, code, generate.…I'll choose constructor,…then I'll select all three fields and click okay,…and that adds the required constructor.…To make this really easy to use,…I'll also add a no arguments constructor,…using the same tool.…And now I can either create a clean instance of the class,…or I can create an instance and pass in the values.…
Author
Released
9/1/2016- Configuring Android Studio
- Understanding fragments
- Creating a fragment class and layout
- Adding and removing fragments with Java
- Creating layouts for multiple screens
- Understanding arguments and callback methods
- Passing arguments to a fragment
- Choosing layout at runtime
- Displaying dialogs with fragments
- Using fragments for managing dialogs, shared preferences, and more
Skill Level Intermediate
Duration
Views
-
Introduction
-
Welcome1m 4s
-
What you should know1m 50s
-
Using the exercise files1m 39s
-
-
1. Getting Started
-
Understanding fragments3m 17s
-
2. Display Fragments in Activities
-
Display a fragment with XML3m 16s
-
Add a fragment with Java3m 50s
-
3. Manage Fragments at Runtime
-
Pass arguments to a fragment5m 18s
-
Choose layout at runtime3m 21s
-
-
4. Communication between Fragments and Activities
-
5. Display Dialogs with Fragments
-
Display a custom dialog5m 1s
-
Pass arguments to the dialog4m 16s
-
6. Other Uses of Fragments
-
Create a ViewPager adapter4m 53s
-
Conclusion
-
Next steps1m 11s
-
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.
CancelTake notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.
Share this video
Embed this video
Video: Send parcelable objects to a fragment