首页 > 系统 > Android > 正文

Android 中 onSaveInstanceState()使用方法详解

2019-12-12 02:05:03
字体:
来源:转载
供稿:网友

Android 中 onSaveInstanceState()使用方法详解

覆盖onSaveInstanceState方法,并在onCreate中检测savedInstanceState和获取保存的值

@Override protected void onSaveInstanceState(Bundle outState) {    outState.putInt("currentposition", videoView.getCurrentPosition());   super.onSaveInstanceState(outState); } 
public void onCreate(Bundle savedInstanceState) {   super.onCreate(savedInstanceState);   setContentView(R.layout.main);    initView();   if (savedInstanceState != null       && savedInstanceState.getInt("currentposition") != 0) {     videoView.seekTo(savedInstanceState.getInt("currentposition"));   } } 

如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表