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
What is the difference between match_parent and fill_parent?
How to reduce APK package size?
FCM Not Receiving Notifications in Android - RRutors
Permission denied for window type 2010 in Marshmallow device
Key Points to remember while develop the Android Application.
What is "shared preferences" in Android ?
Hide/Disable soft keyboard on Activity launch: Android
Explain Fragment Life Cycle
Add Jar/Library Files as Dependency in Android Studio
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
How to Generate signed apk with android studio
How to Get bitmap from drawable: Android
Fix Android Emulator Kill Error When Running Your App
How to get complete address from latitude and longitude?
Fix Duplicate Files in APK Build.gradle Issue - RRutors
How To Set Text Color Programmatically Android TextView?
ERR_ACCESS_DENIED in Android Webview with sdk 30
What is Application?
How to Use Deprecated Handler() in Android - RRutors Guide
What is Context?
What is NetworkOnMainThread Exception?
What are the notifications available in android?
How do I generate random numbers in Dart?
How to check Android version?
What happens next when the device switches between portrait and landscape?
Invoke-customs are only supported starting with android 0 --min-api 26
Android Studio project R can't find
What is the Different Between val and var in Kotlin?
Extract Date and Time from Long Type Variable - RRutors
How to convert milli seconds to hours, minutes and seconds in Android?
How to convert DP to Pixel and Pixel to Dp?
What is ANR? How to avoid and resolve it?
What are Android Versions available?
What is Android Fragments?
How can i comment inside xml file in android studio?
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
How to avoid multiple button click at same time in android?
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 get screen size (width,height) in Android?