Before Architecture Components we were used to save the UI state by onSaveInstanceState() method SaveInstanceState: We need to override onSaveInstanceState(Bundle savedInstanceState) and store the application state values in the form of bundle @Override savedInstanceState.putBoolean("mybool", true); } Saved instanceState could save only parceble data. ViewModel ViewModel instance is part of Applications process and hence it is able to handle configuration changes.
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
savedInstanceState.putInt("myint", 1);
savedInstanceState.putString("mystring", "Back to Activity State");
This have limit to staore small amount of parceble data
If process dies, ViewModel instance lost and all the saved state will also be lost.
It will work for large objects also.
Don't have any restritions to save the state.
You can read about Viewmodel here
How to find Android Device UDID or unique ID?
How to get an image resource by it's name in android?
Add Jar/Library Files as Dependency in Android Studio
What are Android Versions available?
How to convert DP to Pixel and Pixel to Dp?
How to save activity State in Android?
ERR_ACCESS_DENIED in Android Webview with sdk 30
FCM Not Receiving Notifications in Android - RRutors
How can i comment inside xml file in android studio?
How To Set Text Color Programmatically Android TextView?
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
What is ANR in android?
How to install/ uninstall apk by command line ADB
Android Studio project R can't find
What happens next when the device switches between portrait and landscape?
How to start a new activity on button click
Fix Android Emulator Kill Error When Running Your App
What is Application?
How to avoid multiple button click at same time in android?
What is the difference between match_parent and fill_parent?
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
How to get screen size (width,height) in Android?
What is "shared preferences" in Android ?
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
How to validate email address in Android with Kotlin?
How to Exit android app on back pressed?
How do I generate random numbers in Dart?
How to Generate signed apk with android studio
Set Activity to Fullscreen Mode in Android - RRutors
Fix Duplicate Files in APK Build.gradle Issue - RRutors
Invoke-customs are only supported starting with android 0 --min-api 26
Fix Play Store Rejection Due to SMS Permission - RRutors
How do i load image from drawable folder in Jetpack Compose?
What is Android?
What is NetworkOnMainThread Exception?
How to check Android version?
How to get a contact image using a phone number in android?
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
How to stop EditText focus at Activity startup in Android?
How to reduce APK package size?