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 reduce APK package size?
How to check Android version?
What is Android?
How to Generate signed apk with android studio
How do i load image from drawable folder in Jetpack Compose?
Extract Date and Time from Long Type Variable - RRutors
What is the difference between match_parent and fill_parent?
FCM Not Receiving Notifications in Android - RRutors
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
How to get screen size (width,height) in Android?
Open PDF in Google Drive with Intent in Android - RRutors
How to convert DP to Pixel and Pixel to Dp?
What are the notifications available in android?
What happens next when the device switches between portrait and landscape?
What is Intent? What is the difference between an implicit intent and an explicit intent?
How to install/ uninstall apk by command line ADB
How to convert milli seconds to hours, minutes and seconds in Android?
Invoke-customs are only supported starting with android 0 --min-api 26
Key Points to remember while develop the Android Application.
Fix Play Store Rejection Due to SMS Permission - RRutors
How to avoid multiple button click at same time in android?
How to Exit android app on back pressed?
Symmetric vs Asymmetric Encryption in Android Server - RRutors
How to find Android Device UDID or unique ID?
Add Jar/Library Files as Dependency in Android Studio
What is ANR in android?
How to get an image resource by it's name in android?
What are Android Versions available?
Explain Fragment Life Cycle
Fix Android Emulator Kill Error When Running Your App
What is NetworkOnMainThread Exception?
Set Activity to Fullscreen Mode in Android - RRutors
How to copy database from assets folder in android using kotlin
How to Get bitmap from drawable: Android
Android Studio project R can't find
What is Context?
Decompile APK Files: How to Get Source Code - RRutors Guide
What is Application?
Fix Duplicate Files in APK Build.gradle Issue - RRutors