The LoginPreferences is used to persist data with sharedPreference.
private const val PREF_LOGIN_NAME = "loginName"
private const val PREF_LOGIN_PASS = "loginPass"
object LoginPreferences {
    fun getStoredName(context: Context): String {
        val prefs = PreferenceManager.getDefaultSharedPreferences(context)
        return prefs.getString(PREF_LOGIN_NAME, "")!!
    }
    fun setStoredName(context: Context, query: String) {
        PreferenceManager.getDefaultSharedPreferences(context)
            .edit()
            .putString(PREF_LOGIN_NAME, query)
            .apply()
    }
    fun getStoredPass(context: Context): String {
        val prefs = PreferenceManager.getDefaultSharedPreferences(context)
        return prefs.getString(PREF_LOGIN_PASS, "")!!
    }
    fun setStoredPass(context: Context, query: String) {
        PreferenceManager.getDefaultSharedPreferences(context)
            .edit()
            .putString(PREF_LOGIN_PASS, query)
            .apply()
    }
}
The LoginViewModel is a ViewModel use sharedPreferences to be observable data binding in fragment_login.xml.
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <data>
        <variable
            name="loginViewModel"
            type="com.example.login.LoginViewModel" />
    </data>
    <androidx.constraintlayout.widget.ConstraintLayout>
        ...
    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>
But if I want LoginViewModel to work with sharedPreference and observable data binding, it report a one super class error.
// (private val app: Application) : AndroidViewModel(app) is used to access to the sharedPreference.
// BaseObservable() is used to observe the data binding in xml file.
class LoginViewModel(private val app: Application) : AndroidViewModel(app), BaseObservable() {
    ...
}