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 start a new activity on button click
What is ANR in android?
How to get screen size (width,height) in Android?
How to Exit android app on back pressed?
Symmetric vs Asymmetric Encryption in Android Server - RRutors
What is Application?
FCM Not Receiving Notifications in Android - RRutors
Fix Duplicate Files in APK Build.gradle Issue - RRutors
What happens next when the device switches between portrait and landscape?
How do I generate random numbers in Dart?
Permission denied for window type 2010 in Marshmallow device
Key Points to remember while develop the Android Application.
How to convert DP to Pixel and Pixel to Dp?
How to Generate signed apk with android studio
How to validate email address in Android with Kotlin?
What is NetworkOnMainThread Exception?
What is "shared preferences" in Android ?
ERR_ACCESS_DENIED in Android Webview with sdk 30
How to avoid multiple button click at same time in android?
How do i load image from drawable folder in Jetpack Compose?
How to get an image resource by it's name in android?
How To Set Text Color Programmatically Android TextView?
What is Android Fragments?
What is Android?
How to get a contact image using a phone number in android?
Extract Date and Time from Long Type Variable - RRutors
Set Activity to Fullscreen Mode in Android - RRutors
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
Explain Fragment Life Cycle
What is ANR? How to avoid and resolve it?
Add Jar/Library Files as Dependency in Android Studio
Open PDF in Google Drive with Intent in Android - RRutors
What are Android Versions available?
How to get complete address from latitude and longitude?
How to stop EditText focus at Activity startup in Android?
How to save activity State in Android?
What is the Different Between val and var in Kotlin?
Hide/Disable soft keyboard on Activity launch: Android
How to check Android version?
How do I check in SQLite whether a table exists?