1. class PersistentState中,添加数据及起动FragmentHideShow
@Override
protected void onPause() {
super.onPause();
SharedPreferences.Editor editor = getSharedPreferences("share", 0).edit();
editor.putString("text", mSaved.getText().toString());
editor.putInt("selection-start", mSaved.getSelectionStart());
editor.putInt("selection-end", mSaved.getSelectionEnd());
editor.commit();
// 创建一个带“收件人地址”的 email
Bundle bundle =new Bundle();// 创建 email 内容
bundle.putBoolean("boolean_key", true);// 编写内容
bundle.putString("string_key", "string_value");
Intent intent =new Intent(this.getBaseContext(), FragmentHideShow.class);
intent.putExtra("key", bundle);// 封装 email
intent.putExtra("string_key", "hello world");
intent.putExtra("boolean_key", true);
startActivity(intent);
}
2. class FragmentHideShow中接收数据
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.fragment_hide_show);
Intent intent = getIntent();
Bundle bundle = intent.getBundleExtra("key");
Boolean b = bundle.getBoolean("boolean_key");
String val = bundle.getString("string_key");
String val2 = intent.getStringExtra("string_key");
Boolean b2 = intent.getBooleanExtra("boolean", true);
SharedPreferences prefs = this.getSharedPreferences("share", 0);
String restoredText = prefs.getString("text", "march");
setProgressBarIndeterminateVisibility(true);
// 明确进度条
/*requestWindowFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.fragment_hide_show);
setProgress(5000);*/
// The content view embeds two fragments; now retrieve them and attach
// their "hide" button.
FragmentManager fm = getFragmentManager();
addShowHideListener(R.id.frag1hide, fm.findFragmentById(R.id.fragment1));
addShowHideListener(R.id.frag2hide, fm.findFragmentById(R.id.fragment2));
}