summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorArnaud Berry <arnaudberry@google.com>2019-05-06 11:45:31 -0700
committerArnaud Berry <arnaudberry@google.com>2019-05-06 11:45:31 -0700
commit72b99be2b86f7dc5d0d332d5c195eafd4f6beec1 (patch)
tree1ecbb4a95897d988763ccc7332ac8f7b429782b7 /src
parent1d83275fc171e0b67cb8ace9db2ccfacc9720c09 (diff)
downloadMedia-72b99be2b86f7dc5d0d332d5c195eafd4f6beec1.tar.gz
Fix application restarting after being killed.
Fixes: 132076644 Test: manual Change-Id: Idc2ca4cb4c424a92515c5fd4ed21fe0b51fb17f4
Diffstat (limited to 'src')
-rw-r--r--src/com/android/car/media/MediaActivity.java12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/com/android/car/media/MediaActivity.java b/src/com/android/car/media/MediaActivity.java
index 065e837..452df56 100644
--- a/src/com/android/car/media/MediaActivity.java
+++ b/src/com/android/car/media/MediaActivity.java
@@ -181,7 +181,11 @@ public class MediaActivity extends FragmentActivity implements BrowseFragment.Ca
MediaSourceViewModel mediaSourceViewModel = getMediaSourceViewModel();
PlaybackViewModel playbackViewModel = getPlaybackViewModel();
ViewModel localViewModel = getInnerViewModel();
- if (savedInstanceState == null) {
+ // We can't rely on savedInstanceState to determine whether the model has been initialized
+ // as on a config change savedInstanceState != null and the model is initialized, but if
+ // the app was killed by the system then savedInstanceState != null and the model is NOT
+ // initialized...
+ if (localViewModel.needsInitialization()) {
localViewModel.init(playbackViewModel);
localViewModel.setMode(Mode.BROWSING);
}
@@ -527,6 +531,7 @@ public class MediaActivity extends FragmentActivity implements BrowseFragment.Ca
}
public static class ViewModel extends AndroidViewModel {
+ private boolean mNeedsInitialization = true;
private LiveData<Bitmap> mAlbumArt;
private MutableLiveData<Size> mAlbumArtSize = new MutableLiveData<>();
private PlaybackViewModel mPlaybackViewModel;
@@ -556,6 +561,11 @@ public class MediaActivity extends FragmentActivity implements BrowseFragment.Ca
});
mIsErrorState.setValue(false);
+ mNeedsInitialization = false;
+ }
+
+ boolean needsInitialization() {
+ return mNeedsInitialization;
}
void setAlbumArtSize(int width, int height) {