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

How do I carry one intent into 2 different activities?

I want to create and Intent that carries one activity to two separate Blank activities.

2 Answers

In general, an activity represents a screen for your application. So, it does not make sense to start an intent for two different activities, because you should only have one active activity at a time.

I want to pass the same string to two different activities

In order to pass a String into multiple activities, all you have to do is create a new string in the "strings.xml file located in your application directory. The path to the file should look similar to this:

applicationName/res/values/strings.xml 

Create your string which should look similar to this:

<string name="general_error">Sorry, there was an error!</string>

After that, in whichever activity you are in, you may call your string simply by entering the id of said string in whichever block of code you want. Here I made a Toast and called a string on it to alert the user of an error.

Toast.makeText(this, R.string.general_error, Toast.LENGTH_LONG).show();

I hope this helps.