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

I think I am having a problem with the Log.d(TAG,name) When I run the project it says "Unfortunately Stopped"

Intent intent = getIntent();
        String name = intent.getStringExtra("name");
Suleyman Orazgulyyev
Suleyman Orazgulyyev
Pro Student 5,797 Points

It seems good, are you sure that the String that you are providing to the getStringExtra was used as the key in the activity that the intent was sent from? I mean did you do that when you were sending the intent:

intent.putExtra("name", yourstring)

Because the String (which acts as a key) that you provide in putExtra has to be the same in getStringExtra.

christopher irwin
christopher irwin
1,540 Points

I had the same problem it looks like the video jumps or skips on a link of code that I did not see get typed in. Double check the last three lines.

2 Answers

Steve Hunter
Steve Hunter
Treehouse Moderator 57,656 Points

Hi there,

Your code looks fine as long as two things have been added - these are in the video.

You start in the MainActivity where you add a string value to the intent using putExtra and the key called name. You're then using the key to get the data out of the intent in StoryActivity. So, you need to have used the key "name" for this to work - the key must be identical in both activities.

Second, you need to have added the constant called TAG to the top of your class. That way the Log.d knows what TAG is. This line is added at 2:07 in the video.

I hope that helps. If not, in the Android Log, where you're expecting your message to appear, you should get an error message which explains why your app "unfortunately stopped". Post those error messages in here. They'll tell us why your app crashed.


Marc Reid
Marc Reid
7,830 Points

Newer versions of Android Studio seem to prefer you to use...

import static android.util.Log.d;

and then

d(TAG, name);

for some reason following the video exactly produces an error.