1

i have a problem, i have to recall the value of a string from the main class to a secondary class, how can i access to the string on the main class from the second? I got a first Class(LoginActivity) and a second class(DashboardActivity) I have to take the returning value of the LoginActivity (string username) in the dashboard, how can i do this?

0

1 Answer 1

2

When launching DashboardActivity, pass the String value as an Intent.EXTRA.

When launching:

Intent i = new Intent(getBaseContext(), DashboardActivity.class);   
i.putExtra("MyString", username);

And to get the value:

Bundle bundle = getIntent().getExtras();
String value = bundle.getString("MyString");
Sign up to request clarification or add additional context in comments.

2 Comments

since the answer may not be clear, when you create an intent to start the next activity you call intent.putExtra(key, value);
@toadzky I've added sample code. Thanks for the comment though!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.