//-------------------------Activity1----------------------------------
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, testActivity.class);
intent.putExtra("T", "带参数传送");
startActivityForResult(intent, 1);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
text.setText("" + data.getStringExtra("T"));
}
//-------------------------Activity2----------------------------------
Intent intent = getIntent();
text.setText("" + intent.getStringExtra("T"));
}
@Override
public void onBackPressed() {
Intent intent = new Intent();
intent.putExtra("T", "带参数返回");
setResult(2, intent);
finish();
}
转载请注明原文地址: https://ju.6miu.com/read-1000257.html