展示Activity间的迁移方法
共有3个画面:RedirectEnter ,RedirectMain ,RedirectGetter
RedirectEnter -----> RedirectMain
Intent intent = new Intent(RedirectEnter.this, RedirectMain.class);
startActivity(intent);
显示发送Intent,指定迁移目的画面
RedirectMain -----> RedirectGetter
Intent intent = new Intent(RedirectMain.this, RedirectGetter.class);
startActivityForResult(intent, NEW_TEXT_REQUEST);
启动时,使用startActivityForResult,以接收RedirectGetter画面的返回值
画面RedirectGetter并用SharedPreferences将值保存,然后返回RESULT_OK
SharedPreferences preferences = getSharedPreferences("RedirectData", 0);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("text", mText.getText().toString());
if (editor.commit()) {
setResult(RESULT_OK);
}
画面RedirectMain根据返回code读取SharedPreferences数据
if (resultCode != RESULT_CANCELED) {
loadPrefs();
}