Ma2340
Ma2340

Reputation: 727

Android viewModel savedStateHandle

This is more of a conceptual question.

Android recently introduced the concept of handling the state during process death inside viewModel rather than savedInstanceState which previously used to be in Activity or Fragment.

My question is how do I test this process death? If I rightly understand the documentation, the Process death happens to be Android killing the app due to full memory when app is no longer used in background.

Also will the viewModel save the state when user kills the app from the RAM? So that I can retrieve the state as the user opens the app again.

Upvotes: 3

Views: 2834

Answers (2)

Anandaraja_Srinivasan
Anandaraja_Srinivasan

Reputation: 598

Below Steps helps in testing the intelligence of View Model Saved State Library

Step 1: After completing the source code changes, build and run the APP.
Step 2: Ensure UI of Activity/Fragment has data populated in it.
Step 3: Move the App to background by clicking Home Button.
Step 4: Now Open the Logcat Tool window and Terminate the APP.
Step 5: Relaunch the APP from the Device or Emulator.
Step 6: You should see all the data pre-populated in UI.

Upvotes: 0

CHAN
CHAN

Reputation: 1566

enter image description here

  1. Enable `Don't keep activities'
  2. Launch your app
  3. Tap the home button
  4. Your app will be killed immediately (Activity.onDestroy called)

Upvotes: 3

Related Questions