Fragment Arguments

Every fragment instance can have a Bundle object attached to it. This bundle contains key-value pairs that work just like the intent extras of an Activity. Each pair is known as an argument.

To create fragment arguments, you first create a Bundle object. Next, you use type-specific put methods of Bundle (similar to those of Intent) to add arguments to the bundle.

 ​ ​ ​ ​B​u​n​d​l​e​ ​a​r​g​s​ ​=​ ​n​e​w​ ​B​u​n​d​l​e​(​)​;​
 ​ ​ ​ ​a​r​g​s​.​p​u​t​S​e​r​i​a​l​i​z​a​b​l​e​(​E​X​T​R​A​_​M​Y​_​O​B​J​E​C​T​,​ ​m​y​O​b​j​e​c​t​)​;​
 ​ ​ ​ ​a​r​g​s​.​p​u​t​I​n​t​(​E​X​T​R​A​_​M​Y​_​I​N​T​,​ ​m​y​I​n​t​)​;​
 ​ ​ ​ ​a​r​g​s​.​p​u​t​C​h​a​r​S​e​q​u​e​n​c​e​(​E​X​T​R​A​_​M​Y​_​S​T​R​I​N​G​,​ ​m​y​S​t​r​i​n​g​)​;​

Attaching arguments ...

Get Android Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.