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?
1 Answer
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");
2 Comments
toadzky
since the answer may not be clear, when you create an intent to start the next activity you call
intent.putExtra(key, value);Raghav Sood
@toadzky I've added sample code. Thanks for the comment though!