google-developer-training / android-advanced

Solution apps for the apps that students create as they work through the Advanced Android Development training course created by Google Developer Training.
Other
1.14k stars 1.09k forks source link

Advanced Android: [Lesson 13.1][Step 1.5][save current position] #45

Open BartekBlachura opened 1 year ago

BartekBlachura commented 1 year ago

Describe the problem The example says to save current position like this:

@Override
protected void onSaveInstanceState(Bundle outState) {
   super.onSaveInstanceState(outState);

   outState.putInt(PLAYBACK_TIME, mVideoView.getCurrentPosition());
}

but onSaveInstanceState call comes after onPause, so mVideoView.getCurrentPosition() is 0. I think it will be better:

@Override
    protected void onPause() {
        super.onPause();
        currentPosition = videoView.getCurrentPosition();
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
            videoView.pause();
        }
    }

@Override
    protected void onSaveInstanceState(@NonNull Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putInt(PLAYBACK_TIME, currentPosition);
    }

In which lesson and step of the codelab can this issue be found? Lesson number + step number. (e.g., Lesson 13.1, Step 1.5)

Versions Android Studio Dolphin | 2021.3.1 Patch 1 problem found on API 28

codelab: advanced-android