0

I'm having a problem where I just don't know how to save input user data and then recall it. Let's say I want to store someone's name, so I believe I would use an Edit Text box, but that's all I can really figure out. I then later want to display that information in another activity. If you could link me to something or guide me in the right direction it would meant the world to me.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Fernando
  • 450
  • 1
  • 7
  • 22
  • it would be nice if you use sqllite for this purpose and passing data from one activity to another you may use intents. Sqlite tut (http://www.androidhive.info/2011/11/android-sqlite-database-tutorial) and for intents see [this](http://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android) – android_guy Oct 12 '13 at 02:51

3 Answers3

0

Well if you want persistent storage even after the user closed the app, SQLite or sharedpreferences is for you. Otherwise you can juse use Bundles to pass around the small bit of data in intents when starting a new activity. SQLite guide,Sharedpreferences guide. Hope these helped.

kabuto178
  • 3,129
  • 3
  • 40
  • 61
0

Use an EditText to allow the user to input their name. Get the value from the EditText component via the EditText's getText() method. After that you have lot of different ways you can go. Save it for later or just pass it on via an intent to the next activity.

Good luck.

eimmer
  • 319
  • 1
  • 3
  • 13
0

The term "Storing" should have a scope. Say, you are gonna store the data for a specific code block, or at activity level, or at application level, or you want persistent(storing data in Preferences or Database, for example, storing the game score, etc) or non-persistent(temporary storage: declaring the variables in the activity) storage.

In your case, to get the Text from EditText and send it to next activity:

Declare a global variables,

EditText editText;
String data;

// write this inside onCreate, after the `setContentView()` method
editText = (EditText) findViewById(R.id....);
data = editText.getText().toString();

// say you want to pass the data to next activity on button click, so write this inside //onClick()

Intent intent = new Intent(currentActivityName.this, NextActivityName.class);
intent.putExtra("data", data);
startActivity(intent);

Up till now what we have done is, get text from EditText, and prepared for sending it to next it to next activity. Now, on button click, the data will be sent to next activity.

But on next activity, you need to catch the data, that was sent from previous activity, to use it.

So, in the next activity, write the following code inside onCreate()

Intent intent = getIntent();

String dataReceived = intent.getStringExtra("data");

Log.i("data received", dataReceived);

After doing this check if you got the log, with tag name "data received" and data you sent.

Chintan Soni
  • 24,761
  • 25
  • 106
  • 174