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
Fix Duplicate Files in APK Build.gradle Issue - RRutors
Set Activity to Fullscreen Mode in Android - RRutors
How to start a new activity on button click
How To Set Text Color Programmatically Android TextView?
Extract Date and Time from Long Type Variable - RRutors
How to Get bitmap from drawable: Android
What happens next when the device switches between portrait and landscape?
Explain Fragment Life Cycle
Check List for Generate Signed APK Android
How do i load image from drawable folder in Jetpack Compose?
How to get complete address from latitude and longitude?
How to get a contact image using a phone number in android?
How to reduce APK package size?
How to save activity State in Android?
What is Android Fragments?
ERR_ACCESS_DENIED in Android Webview with sdk 30
Open PDF in Google Drive with Intent in Android - RRutors
How to Exit android app on back pressed?
Android Studio project R can't find
What is Intent? What is the difference between an implicit intent and an explicit intent?
How to find Android Device UDID or unique ID?
How can i comment inside xml file in android studio?
How to avoid multiple button click at same time in android?
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
What are Android Versions available?
What is the Different Between val and var in Kotlin?
Fix Play Store Rejection Due to SMS Permission - RRutors
FCM Not Receiving Notifications in Android - RRutors
How to Generate signed apk with android studio
What is Android?
Add Jar/Library Files as Dependency in Android Studio
Hide/Disable soft keyboard on Activity launch: Android
Symmetric vs Asymmetric Encryption in Android Server - RRutors
What are the notifications available in android?
What is Application?
How to get an image resource by it's name in android?
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
Permission denied for window type 2010 in Marshmallow device
FragmentPagerAdapter deprecated, Since API 27.1.0 FragmentPagerAdapter is deprecated.
How to Use Deprecated Handler() in Android - RRutors Guide