标签:就是 ted art public call ota undle IV lock
https://blog.csdn.net/yuzhiboyi/article/details/7677026
实现并覆盖了onSaveInstanceState方法:
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- // TODO Auto-generated method stub
- outState.putInt("currentposition", videoView.getCurrentPosition());
- Log.v("tag", "onSaveInstanceState");
- super.onSaveInstanceState(outState);
- }
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Log.v("tag", "onCreate");
- if (videoView == null) {
- videoView = (VideoView) this.findViewById(R.id.myvideo);
- MediaController controller = new MediaController(this);
- videoView.setMediaController(controller);
- videoView.setVideoPath(VIDEO_PATH);
- videoView.requestFocus();
- }
- if (savedInstanceState != null
- && savedInstanceState.getInt("currentposition") != 0) {
- videoView.seekTo(savedInstanceState.getInt("currentposition"));
- }
- videoView.start();
- }
onCreate方法中的参数savedInstanceState就是保存的Activity一些状态。
- savedInstanceState.getInt("currentposition")
获取视频播放时间。
红色代码是将当前video的播放时间存储在Bundle中。
用onSaveInstanceState()方法保存Activity状态
标签:就是 ted art public call ota undle IV lock
原文地址:https://www.cnblogs.com/liangxy/p/9150647.html