Activity横竖屏切换时 一些数据的保存

Posted 短暂的火光

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Activity横竖屏切换时 一些数据的保存相关的知识,希望对你有一定的参考价值。

private VideoView videoView;  
02.private static final String VIDEO_PATH = Environment  
03.        .getExternalStorageDirectory()  
04.        + File.separator  
05.        + "mymovie"  
06.        + File.separator + "shenghuaweiji.mp4";  
07.  
08./** Called when the activity is first created. */  
09[email protected]  
10.public void onCreate(Bundle savedInstanceState) {  
11.    super.onCreate(savedInstanceState);  
12.    setContentView(R.layout.main);  
13.    Log.v("tag", "onCreate");  
14.     
15.    if (videoView == null) {  
16.        videoView = (VideoView) this.findViewById(R.id.myvideo);  
17.        MediaController controller = new MediaController(this);  
18.        videoView.setMediaController(controller);  
19.        videoView.setVideoPath(VIDEO_PATH);  
20.        videoView.requestFocus();  
21.    }  
22.  
23.    if (savedInstanceState != null  
24.            && savedInstanceState.getInt("currentposition") != 0) {  
25.  
26.        videoView.seekTo(savedInstanceState.getInt("currentposition"));  
27.    }  
28.    videoView.start();  
29.  
30.}  
@Override  
  • protected void onSaveInstanceState(Bundle outState) {  
  •     // TODO Auto-generated method stub  
  •     outState.putInt("currentposition", videoView.getCurrentPosition());  
  •     Log.v("tag", "onSaveInstanceState");  
  •     super.onSaveInstanceState(outState);  
  • }   

 

以上是关于Activity横竖屏切换时 一些数据的保存的主要内容,如果未能解决你的问题,请参考以下文章

面试题:Activity横竖屏切换时的生命周期如何变化

Activity横竖屏切换

横竖屏切换时activity生命周期变化的总结

横竖屏切换时activity生命周期变化的总结

软件的横竖屏切换

横竖屏切换时候activity的生命周期