状态保存
作者:互联网
1、新创建一个Activty
public class Zhuangtai extends Activity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.zhuangtaisave);
}
2、新创建一个xml文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:id="@+id/baocun"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="保存状态"
android:textSize="22dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
/>
</RelativeLayout>
3、写一个方法。在输入里输入数据时,意外终止止或返回主界面时的数据保存。
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Log.e("message","onSaveInstanceState>>>>>>>>>>>>>>>>>>>>>>>>");
}
4、写一个意外终止或意外返回主界面后,重新打开之后,之前所输入的数据一直存在。
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
Log.e("message","onRestoreInstanceState>>>>>>>>>>>>>>>>>>>>>>>>");
}
标签:状态,void,保存,Bundle,savedInstanceState,onRestoreInstanceState,onSaveInstanceState, 来源: https://blog.51cto.com/u_14397532/3035671