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
Key Points to remember while develop the Android Application.
What is ANR? How to avoid and resolve it?
What is Intent? What is the difference between an implicit intent and an explicit intent?
How to install/ uninstall apk by command line ADB
What is Android?
What are the notifications available in android?
How to get a contact image using a phone number in android?
How to Get bitmap from drawable: Android
Check List for Generate Signed APK Android
ERROR Android emulator gets killed when I try to run my application and choose an emulator it ret
ERR_ACCESS_DENIED in Android Webview with sdk 30
How to start a new activity on button click
Intent for Drive PDF Viewer - How to open PDF in Google Drive with intent
What is Android Fragments?
Hide/Disable soft keyboard on Activity launch: Android
How do i load image from drawable folder in Jetpack Compose?
What is Context?
How to extract date and time from Long type variable in Kotlin on Android "
Android Studio project R can't find
How to reduce APK package size?
How to convert milli seconds to hours, minutes and seconds in Android?
INSTALL_FAILED_INVALID_APK: Split lib_slice_9_apk was defined multiple times. It is possible that th
How to check Android version?
How to get an image resource by it's name in android?
How to copy database from assets folder in android using kotlin
What is the difference between match_parent and fill_parent?
How can i comment inside xml file in android studio?
How to validate email address in Android with Kotlin?
Explain Fragment Life Cycle
How to Exit android app on back pressed?
Android FCM not receiving notifications when app is removed from background
Permission denied for window type 2010 in Marshmallow device
Is There A Way To Get The Source Code From An APK File? (or) How to decompile apk?
What are Android Versions available?
How to add jar/library files as a dependency in Android studio gradle file
How to convert DP to Pixel and Pixel to Dp?
What is "shared preferences" in Android ?
What happens next when the device switches between portrait and landscape?
Android Activity FullScreen - How to set activity to fullscreen mode in Android?
How do I generate random numbers in Dart?