Reputation: 467
I have two Intent
s and two Activity
s.
I have in the first Intent
an EditText
.
I want to use the text in the EditText
in the second intent and pass to the second intent
Intent myIntent = new Intent(mycurentActivity.this, secondActivity.class);
startActivity(myIntent);
Thank you in advance
Upvotes: 9
Views: 6084
Reputation: 71
in the First activity
//...
final static int EDIT=0;
//...(action trigger)
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent;
intent = new Intent().setClass(mycurentActivity.this, secondActivity.class);
startActivityForResult(intent, EDIT);
}
//...
and later in the First activity
//...
protected void onActivityResult(int requestCode, int resultCode, Intent data){
switch(requestCode){
case EDIT:
if(resultCode == RESULT_OK){
String text = data.getStringExtra("key");
//do whatever with the text...
}else if(resultCode == RESULT_CANCELED){
}
break;
}
}
//...
and second activity
//...
Intent intent = new Intent().setClass(secondActivity.this, mycurentActivity.class);
intent.putExtra("key", myEditText.getText().toString);
setResult(RESULT_OK, intent);
finish();
//...
Upvotes: 0
Reputation: 467
First Activity
Intent myIntent = new Intent(rechercheCP.this, XMLParsing.class);
myIntent.putExtra("key", autoComplete.getText().toString());
startActivity(myIntent);
Second Activity
TextView a;
String text = myIntent.getStringExtra("key");
a = new TextView(this);
a.setText(text);
layout.addView(a);
Upvotes: 0
Reputation: 52247
Your looking for Intent#putExtra(String, String).
Here is an example:
Intent myIntent = new Intent(mycurentActivity.this, secondActivity.class);
myIntent.putExtra("key", myEditText.Text.toString();
startActivity(myIntent);
When your receiving the Intent you can extract it again:
String text = myIntent.getStringExtra("key");
(http://developer.android.com/reference/android/content/Intent.html#getStringExtra(java.lang.String))
Upvotes: 12