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
Decompile APK Files: How to Get Source Code - RRutors Guide
Open PDF in Google Drive with Intent in Android - RRutors
Android Studio project R can't find
What is Context?
How do i load image from drawable folder in Jetpack Compose?
Add Jar/Library Files as Dependency in Android Studio
How to Exit android app on back pressed?
How to Get bitmap from drawable: Android
Invoke-customs are only supported starting with android 0 --min-api 26
Hide/Disable soft keyboard on Activity launch: Android
How to copy database from assets folder in android using kotlin
How to stop EditText focus at Activity startup in Android?
What are Android Versions available?
How to check Android version?
What is ANR? How to avoid and resolve it?
How to get screen size (width,height) in Android?
How to convert milli seconds to hours, minutes and seconds in Android?
What happens next when the device switches between portrait and landscape?
What are the notifications available in android?
What is the difference between match_parent and fill_parent?
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
Check List for Generate Signed APK Android
How to Use Deprecated Handler() in Android - RRutors Guide
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
ERR_ACCESS_DENIED in Android Webview with sdk 30
How to reduce APK package size?
Explain Fragment Life Cycle
How to Generate signed apk with android studio
How to start a new activity on button click
How to avoid multiple button click at same time in android?
Extract Date and Time from Long Type Variable - RRutors
What is the Different Between val and var in Kotlin?
What is Intent? What is the difference between an implicit intent and an explicit intent?
What is Android Fragments?
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
How to validate email address in Android with Kotlin?
What is Android?
What is NetworkOnMainThread Exception?
Permission denied for window type 2010 in Marshmallow device
How to get complete address from latitude and longitude?