Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build an Interactive Story App Intents and Multiple Activities Getting Data from an Intent

What exactly getStringExtra() is doing? i dont fully understand yet.

Hi!, as far as i understand this method does this: getStringExtra() retrieve the data (which in our case the name of the user) that previously added with putExtra() method which take a key and the value in the MainActivity?

so in order to get the value in another activity for future use(the name of the user) i need to call a get method on the key?

String name = intent.getStringExtra("name");

is it like a Map in java?

any insights or further explantion will be appericiated

Lauren Moineau

1 Answer

Yes, exactly. Those "extras" we're adding to the intent are stored in a Bundle that maps Key-Value pairs.

Lauren Moineau can u give some examples to the use of this in real apps?

like if i want to make a age calculator app so i use this method to caculate lets say how many days he lived so far in another activity and in order to get the age from the main activity i should use this?