上一个活动:
Intent intent = new Intent(MainActivity.this,SecondActivity.class);
startActivityForResult(intent,1);
下一个活动点击组件的情况:
btn2 = (Button) findViewById(R.id.btn2);
btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.putExtra("data_Result","YES!");
setResult(RESULT_OK,intent);
finish();
}
});
下一个活动点击BACK键的情况
public void onBackPressed() {
Intent intent = new Intent();
intent.putExtra("data_Result","YES!");
setResult(RESULT_OK,intent);
finish();
}
上一个活动接收返回的数据:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode){
case 1:
if(resultCode==RESULT_OK){
String returnData = data.getStringExtra("data_Result");
Log.d("FirstActivity",returnData);
}
break;
default:
}
}