Android 将数据从intent传递到其他intent
我有两个Android 将数据从intent传递到其他intent,android,Android,我有两个Intents和两个Activitys 我在第一个Intent中有一个EditText 我想在第二个意图中使用EditText中的文本,并传递到第二个意图 Intent myIntent = new Intent(mycurentActivity.this, secondActivity.class); startActivity(myIntent); 提前感谢您的寻找 以下是一个例子: Intent myIntent = new Intent(mycurentActivity.th
Intent
s和两个Activity
s
我在第一个Intent
中有一个EditText
我想在第二个意图中使用EditText
中的文本,并传递到第二个意图
Intent myIntent = new Intent(mycurentActivity.this, secondActivity.class);
startActivity(myIntent);
提前感谢您的寻找
以下是一个例子:
Intent myIntent = new Intent(mycurentActivity.this, secondActivity.class);
myIntent.putExtra("key", myEditText.Text.toString();
startActivity(myIntent);
当您收到意图时,您可以再次提取它:
String text = myIntent.getStringExtra("key");
(http://developer.android.com/reference/android/content/Intent.html#getStringExtra(java.lang.String))第一个活动
Intent myIntent = new Intent(rechercheCP.this, XMLParsing.class);
myIntent.putExtra("key", autoComplete.getText().toString());
startActivity(myIntent);
第二项活动
TextView a;
String text = myIntent.getStringExtra("key");
a = new TextView(this);
a.setText(text);
layout.addView(a);
在第一个活动中
//...
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);
}
//...
//...
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;
}
}
//...
然后在第一次活动中
//...
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);
}
//...
//...
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;
}
}
//...
第二项活动
//...
Intent intent = new Intent().setClass(secondActivity.this, mycurentActivity.class);
intent.putExtra("key", myEditText.getText().toString);
setResult(RESULT_OK, intent);
finish();
//...
我像编写代码一样编写代码,然后Eclipse要求我创建一个局部变量Intent并将其初始化为null;然后我运行代码,得到一个空屏幕,提前谢谢。最好是你应该创建一个局部变量int。请显示你的代码。没有方法传递对象吗?这条路真是迂回