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?
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
How to start a new activity on button click
What is Intent? What is the difference between an implicit intent and an explicit intent?
How can i comment inside xml file in android studio?
How to save activity State in Android?
How to convert DP to Pixel and Pixel to Dp?
FCM Not Receiving Notifications in Android - RRutors
How to get complete address from latitude and longitude?
Fix Duplicate Files in APK Build.gradle Issue - RRutors
Explain Fragment Life Cycle
Set Activity to Fullscreen Mode in Android - RRutors
What is Context?
How to Exit android app on back pressed?
How To Set Text Color Programmatically Android TextView?
Hide/Disable soft keyboard on Activity launch: Android
How to avoid multiple button click at same time in android?
Symmetric vs Asymmetric Encryption in Android Server - RRutors
How to get a contact image using a phone number in android?
Add Jar/Library Files as Dependency in Android Studio
Check List for Generate Signed APK Android
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
How do I generate random numbers in Dart?
What is ANR? How to avoid and resolve it?
Key Points to remember while develop the Android Application.
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
Decompile APK Files: How to Get Source Code - RRutors Guide
Fix Android Emulator Kill Error When Running Your App
What is the difference between match_parent and fill_parent?
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
Permission denied for window type 2010 in Marshmallow device
How to copy database from assets folder in android using kotlin
What are Android Versions available?
How to find Android Device UDID or unique ID?
What is ANR in android?
How do I check in SQLite whether a table exists?
What is NetworkOnMainThread Exception?
What is the Different Between val and var in Kotlin?
What is Android?
What are the notifications available in android?