Activity被系统回收前保存临时数据:
@Override
protected void onSaveInstanceState(Bundle outState){
super.onSaveInstanceState(outState);
String tempData = "Something you just typed";
outState.putString("data_key",tempData);
}
恢复保存的临时数据:
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(saveInstanceState);
Log.d(TAG,"onCreate");
setContentView(R.layout.activity_main);
if(savedInstanceState != null){
String tempData = saveInstanceState.getString("data_key");
Log.d(TAG,tempData);
}
....
}