0

I have a login page which requires user to enter their name. On the next page, I'm trying to show "Hi, (name)". How can I do that? And can I store this permanently like, when the user restarts the app, it does not require them to key in their name anymore?

user3774763
  • 125
  • 1
  • 1
  • 8

2 Answers2

1

You need to get the name from the text view:

String name = mTextview.getText();

When you launch the next activity you can say:

Intent intent = new Intent(this, NextActivity.class);
intent.putExtra("NAME", name);
startActivity(intent);

In next Activity you can get it using:

Bundle extra = getIntent().getExtras();
String name = extra.getStringExtra("NAME");

Another approach, if you want to store it permanently, you can use SharedPreferences.

AlexBalo
  • 1,258
  • 1
  • 11
  • 16
1

You can use SharedPreference, like they said.

example :

SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("uName", txtUname.getText());
editor.commit(); 

When required, you can use 'getString("uName")' in place of putString() to read the value.

A stack-overflow link that might help you in-case of any confusions.

Android - Storing/retrieving strings with shared preferences

Community
  • 1
  • 1
Priyabrata
  • 1,202
  • 3
  • 19
  • 57