Examples of Intent and Bundles
2312
18-Jan-2016
I need a simple example code that will show me the difference between Intents and Bundles
Updated on 27-Jun-2023
Aryan Kumar
27-Jun-2023Sure, 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.Anonymous User
18-Jan-2016