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
ERR_ACCESS_DENIED in Android Webview with sdk 30
What is Intent? What is the difference between an implicit intent and an explicit intent?
Extract Date and Time from Long Type Variable - RRutors
Fix Android Emulator Kill Error When Running Your App
What is ANR in android?
How to find Android Device UDID or unique ID?
Add Jar/Library Files as Dependency in Android Studio
How to get screen size (width,height) in Android?
Decompile APK Files: How to Get Source Code - RRutors Guide
Open PDF in Google Drive with Intent in Android - RRutors
What is Context?
What is NetworkOnMainThread Exception?
How to start a new activity on button click
How to install/ uninstall apk by command line ADB
What is the difference between match_parent and fill_parent?
How to get an image resource by it's name in android?
How do i load image from drawable folder in Jetpack Compose?
How to copy database from assets folder in android using kotlin
What are Android Versions available?
How to get a contact image using a phone number in android?
How to convert milli seconds to hours, minutes and seconds in Android?
Fix Play Store Rejection Due to SMS Permission - RRutors
Hide/Disable soft keyboard on Activity launch: Android
Key Points to remember while develop the Android Application.
What are the notifications available in android?
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
Check List for Generate Signed APK Android
Set Activity to Fullscreen Mode in Android - RRutors
How to reduce APK package size?
Fix Duplicate Files in APK Build.gradle Issue - RRutors
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
Android Studio project R can't find
What happens next when the device switches between portrait and landscape?
What is Application?
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
How to check Android version?
FCM Not Receiving Notifications in Android - RRutors
What is ANR? How to avoid and resolve it?
What is "shared preferences" in Android ?
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr