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

Ephraim Smith
Ephraim Smith
9,835 Points

Logcat Debugging not working

When attempting to debug via [Log.d(TAG, variable);], the following 2 lines appear first in my Logcat:

"Not late-enabling -Xcheck:jni (already on)" "Unexpected CPU variant for X86 using defaults: x86"

And of course I don't see the Log.d output in the Logcat.

Thanks for your help guys.

Hi. Does your app run OK or does it crash? As for the Log.d, could you paste your code here, please? Thanks

Ephraim Smith
Ephraim Smith
9,835 Points

Hey Lauren,

So, I got the debugger to work. Now, I can't get the app to return user's name at placeholder. Program always returns "friend."

        Intent intent = getIntent();
        name = intent.getStringExtra("name");      //  *** START ADVENTURE DOESN'T INSERT USER'S NAME ***
        if(name == null || name.isEmpty()) {
            name = "Friend";
        }
        Log.d(TAG, name);           //  <-- TEST DRIVEN DEVELOPMENT:)

        story = new Story();
        loadPage(0);

Debugger shows [D/StoryActivity: Friend]

Here's what the other end looks like...

startButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String name = nameField.getText().toString();
                startStory(name);
            }
        });
    }

    private void startStory(String name) {
        Intent intent = new Intent(this, StoryActivity.class);  //  <-- [INTENT OBJECT]this is how an action sends user to another activity

        Resources resources = getResources();
        String key = resources.getString(R.string.key_name);

        intent.putExtra(key, name);  // <-- [EXTRAS: "intent" data] used to pass variable(s)/data to next activity via KEY VALUE PAIR
        startActivity(intent);
    }

Thanks for replying!

Hi Ephraim. Glad to hear you solved your previous issue. Your code looks fine to me. I even copy pasted it and it works my side: every time I enter a name in the edit text, it logs it in the Logcat.

Maybe you want to double check your key_name string in your strings.xml resource file. Just make sure its value is name. Since you're referring to that key as "name" and are not using the string from the resource file in StoryActivity, if they don't have the same value, that could be the reason you always get Friend as you wouldn't be getting the value from the intent (name would be null because you'd be using 2 different keys).

1 Answer

Ephraim Smith
Ephraim Smith
9,835 Points

You're awesome. That's exactly what it was. Have a good rest of your day. Thanks!

You're welcome :) I'm glad it's fixed. Thank you. Have a great end of day too