Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

gabriel wambua
gabriel wambua
5,061 Points

How do we know which intent an activity will get from another activity?

My question is simple.

I can see that once you pass data through an intent from one activity to the next that you can use getIntent(); to retrieve the data in the next intent. What I dont get is what do you do if you have more that one activity sending data through intents to a particular activity. How do you distinguish between the different intents?

For example MainActivity(assuming this is the first activity) uses an intent fromMaintoActivity2 with a putExtra that carries a name string. Then another activity e.g. ProfileActivity with an intent fromProfiletoActivity2 uses putExtra to send a gender string.

When retrieving the information in Activity2 how do we distinguish the data from the two activities?

1 Answer

Well as you may know from working with intents when you send an intent with putExtra you also determine a key. I would then guess that from that key android studio can determine which intent to use.