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
ERROR Android emulator gets killed when I try to run my application and choose an emulator it ret
Android Activity FullScreen - How to set activity to fullscreen mode in Android?
How do i load image from drawable folder in Jetpack Compose?
How can i comment inside xml file in android studio?
ERR_ACCESS_DENIED in Android Webview with sdk 30
How to start a new activity on button click
What is Context?
How To Set Text Color Programmatically Android TextView?
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
How to Exit android app on back pressed?
Intent for Drive PDF Viewer - How to open PDF in Google Drive with intent
What is ANR? How to avoid and resolve it?
How to validate email address in Android with Kotlin?
How to add jar/library files as a dependency in Android studio gradle file
Permission denied for window type 2010 in Marshmallow device
How to Generate signed apk with android studio
What are symmetric and asymmetric encryption in the way Android interacts with the server?
Hide/Disable soft keyboard on Activity launch: Android
Could not inflate Behavior subclass android.support.design.widget. BottomSheetBehavior How resolve
What are Android Versions available?
What happens next when the device switches between portrait and landscape?
What is the difference between match_parent and fill_parent?
'constructor Handler()' is deprecated. Deprecated in Java, How to use Handler() class in And
How do I generate random numbers in Dart?
What is ANR in android?
How to reduce APK package size?
Android Studio project R can't find
How to get a contact image using a phone number in android?
How to convert DP to Pixel and Pixel to Dp?
Key Points to remember while develop the Android Application.
Duplicate files during packaging of APK” build.gradle issue: Android Studio
How to avoid multiple button click at same time in android?
How to install/ uninstall apk by command line ADB
What is NetworkOnMainThread Exception?
How to save activity State in Android?
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
How do I check in SQLite whether a table exists?
Invoke-customs are only supported starting with android 0 --min-api 26
What is Intent? What is the difference between an implicit intent and an explicit intent?
Check List for Generate Signed APK Android