St3v3 Al
St3v3 Al

Reputation: 91

How to display a welcome message including username from another activity in android?

Here is what I want to do, I have an android login form with username and password, after the user enters his credentials and login, the next form should display on top of the page welcome,+username entered from the login page! can someone please help me??

I'm new to android development and don't know how to go about this. Thanks

Upvotes: 1

Views: 5180

Answers (3)

Raghunandan
Raghunandan

Reputation: 133560

You can use intent to pass username from one activity to another.

Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
intent.putExtra("username","enteredusername");
startActivity(intent);

And in SecondActivity

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

Now use the name and display the welcome +name

http://developer.android.com/training/basics/firstapp/starting-activity.html

Upvotes: 1

naidu
naidu

Reputation: 350

You can store the username in sqlite or sharedpreferences to get the username across all your application.

Upvotes: 0

laminatefish
laminatefish

Reputation: 5246

In order to send data from one activity to another, you need to use intents. So, in your login activity, you would launch your welcome activity like this:

Intent intent = new Intent(LoginActivity.this, WelcomeActivity.class);
intent.putextra("userName","value");
startActivity(intent);

Then, in your welcome activity, you need to retrieve the extra data, like so:

String data= getIntent().getStringExtra("userName");

There are a multitude of examples that can be found via Google, and many questions similar/identical to this have been answered previously on SO.

Upvotes: 0

Related Questions