Ms. B Ms. B - 2 months ago 6
Android Question

How to get the current user name from login in android

I have an android form which consists of a login and the main file.
What I want to ask is how to get the current username and display it in the main xml file.

Like for example, I logged in as "james01" and when I click the log in button, I will be redirected to the next page and in the next page there is "Welcome james01"

I kinda need your help on this.

Answers are always welcome ^^

Answer

The easiest way to do this is to pass the username to the 2nd activity in the intent you're using to start the activity:

Intent intent = new Intent(getBaseContext(), SecondActivity.class);
intent.putExtra("USERNAME", username);
startActivity(intent);

Then in the second activity:

String username = getIntent().getStringExtra("USERNAME");

check How do I pass data between activities in Android?