答案 0 :(得分:0)
用它来保存
Intent intent = new Intent(FirstScreen.this, SecondScreen.class)
intent .putExtra(strName, keyIdentifer );
用它来获取
String newString;
if (savedInstanceState == null) {
Bundle extras = getIntent().getExtras();
if(extras == null) {
newString= null;
} else {
newString= extras.getString("STRING_I_NEED");
}
} else {
newString= (String) savedInstanceState.getSerializable("STRING_I_NEED");
}
答案 1 :(得分:0)
如果您只想将数据发送到下一个活动,请使用 Intent intent = new Intent(FirstActivity.this,SecondActivity.class) intent.putExtra(" id_for_value",value); startActivity(意向);
用
恢复它 value= getIntent().getExtras().getString("id_for_value");//if it is a string
或强>
如果要将数据从第二个活动发送回上一个活动,则必须使用结果的开始活动
Intent intent=new Intent(MainActivity.this,SecondActivity.class);
startActivityForResult(intent, 2)//where 2 is the request code
finish();
再次在FirstActivity中,除了这个
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
// check if the request code is same as what is passed here it is 2
if(requestCode==2)
{
String result=data.getStringExtra("ResultId");
}
}
在您的PreviousActivity中,您可以传递这样的数据
Intent intent=new Intent();
intent.putExtra("ResultId",message);
setResult(2,intent);
finish();