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 start a new activity on button click
How to get a contact image using a phone number in android?
Explain Fragment Life Cycle
Fix Android Emulator Kill Error When Running Your App
How to find Android Device UDID or unique ID?
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
What is Android Fragments?
Invoke-customs are only supported starting with android 0 --min-api 26
Fix Play Store Rejection Due to SMS Permission - RRutors
How to Use Deprecated Handler() in Android - RRutors Guide
How to copy database from assets folder in android using kotlin
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
What is the Different Between val and var in Kotlin?
How to get an image resource by it's name in android?
Symmetric vs Asymmetric Encryption in Android Server - RRutors
Decompile APK Files: How to Get Source Code - RRutors Guide
Open PDF in Google Drive with Intent in Android - RRutors
How to convert milli seconds to hours, minutes and seconds in Android?
What is NetworkOnMainThread Exception?
Check List for Generate Signed APK Android
How to install/ uninstall apk by command line ADB
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
What is Intent? What is the difference between an implicit intent and an explicit intent?
How to convert DP to Pixel and Pixel to Dp?
Permission denied for window type 2010 in Marshmallow device
Fix Duplicate Files in APK Build.gradle Issue - RRutors
How do I generate random numbers in Dart?
How to get complete address from latitude and longitude?
ERR_ACCESS_DENIED in Android Webview with sdk 30
Android Studio project R can't find
How to get screen size (width,height) in Android?
Key Points to remember while develop the Android Application.
What is Context?
How To Set Text Color Programmatically Android TextView?
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
How to save activity State in Android?
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
How can i comment inside xml file in android studio?
How to stop EditText focus at Activity startup in Android?
How to validate email address in Android with Kotlin?