Fading Coder

One Final Commit for the Last Sprint

Surviving Process Death with Android ViewModel and SavedStateHandle

When Android kills an application in the backgronud, the system may later restore it exactly where the user left off. To keep UI state across this recreation you can combine ViewModel with SavedStateHandle. The handle acts like a tiny key-value bundle that survives both configuration changes and pro...

Using Room with ViewModel and LiveData in Android

Using Room with ViewModel and LiveData in Android
The Room persistence library supports LiveData, which automatical observes database changes. When the database is modified, the onChanged callback is envoked to update the UI. 1. MainActivity package com.example.roomdemo import android.os.Bundle import android.view.View import androidx.appcompat.app...

Using AndroidViewModel to Access Application Context and Persist Data with SharedPreferences

This example demonstrates a basic counter application that retains its state across process death by leveraging AndroidViewModel, SavedStateHandle, and SharedPreferences. AndroidViewModel extends the base ViewModel class and provides access to the application context via getApplication(). This allow...