I want on the first Activity (in the layout to write) what is your name?! when a person write his name when he movie to anther Activity it should appear Hello(THE NAME)! how should i do this?
Asked
Active
Viewed 83 times
2 Answers
3
This is how you call the intent with a parameter
Intent search = new Intent(FirstActivity.this, SecondActivity.class);
search.putExtra("param_a", content1);
startActivity(search);

Alya'a Gamal
- 5,624
- 19
- 34

Hussain Akhtar Wahid 'Ghouri'
- 6,527
- 8
- 50
- 85
-
well the ans was for you to get started , either i copy paste the answer or you refer this link and get complete info :http://stackoverflow.com/questions/4429036/passing-string-array-between-android-activities – Hussain Akhtar Wahid 'Ghouri' May 14 '13 at 13:39
-
the param_a is NAME and content is the valuo? – Eva May 14 '13 at 13:39
-
check the link , hope it explains everything – Hussain Akhtar Wahid 'Ghouri' May 14 '13 at 13:40
-
@down voter : please leave a reason or suggestion for downvote – Hussain Akhtar Wahid 'Ghouri' Oct 09 '13 at 04:52
2
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
//some stuff
//Note : start the activity from an event (onClick per example)
String stringObject = "Foo"; //or a String you get from your editText
Intent i = new Intent(MainActivity.this, OtherActivity.class);
i.putExtra("name", stringObject);
startActivity(i);
}
}
public class OtherActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
//some stuff
Bundle extras = getIntent().getExtras();
String name = "";
if (extras != null){
name = extras.getString("name");
myTextView.setText(name);
}
}
}

Alexis C.
- 91,686
- 21
- 171
- 177
-
Intent i = new Intent(MainActivity.this, OtherActivity.class); i.putExtra("name", is that the name that i have?); startActivity(i); – Eva May 14 '13 at 14:08
-
stringObject represents the name you get of the user. You have to stock this name in a `String` object. Example : `String stringObject="Foo";` – Alexis C. May 14 '13 at 14:09
-
also in the anther activity i have a textview in the layout(what should i do to apper ) the name:a sentence! – Eva May 14 '13 at 14:10
-
-
-
-
Intent i = new Intent(MainActivity.this, OtherActivity.class); i.putExtra("name", stringObject); startActivity(i); thats on the first but on the second i put myTextView.setText(stringObject);stringObject that from the first and when i do this its comes red under stringObject – Eva May 14 '13 at 14:21
-
-