Examples of Intent and Bundles
Ask by Allen Scott
Updated 27 Jun 2023
Sure, here is an example of how to use an Intent and a Bundle to transfer data from one activity to another:
Code snippet
In the second activity, you can retrieve the data that was passed in the Intent using the
getExtras()method.Code snippet
The
datavariable will now contain the string that was passed in the Intent.Here is an example of how to use a Bundle to store a more complex data structure:
Code snippet
In the second activity, you can retrieve the person object from the Bundle using the
getSerializable()method.Code snippet
The
personvariable will now contain the person object that was passed in the Bundle.