Android中如何使用onSaveInstanceState()方法

Android中如何使用onSaveInstanceState()方法,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

成都创新互联专注于当阳网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供当阳营销型网站建设,当阳网站制作、当阳网页设计、当阳网站官网定制、微信小程序开发服务,打造当阳网络公司原创品牌,更为您提供当阳网站排名全网营销落地服务。

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")); 
  } 
}

关于Android中如何使用onSaveInstanceState()方法问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注创新互联行业资讯频道了解更多相关知识。


当前名称:Android中如何使用onSaveInstanceState()方法
文章链接:http://ybzwz.com/article/gjeoph.html