Ch. 4 ViewModel Scoping

I am following through the book and trying to fix the bug with GeoGuesser resetting on rotation. I followed the instructions to scope QuizViewModel to MainActivity but it doesn’t seem to be scoping to it. I do not see the message in logcat when it is initialized. This is the relevant code in Main and QuizViewModel:


override fun onCreate(savedInstanceState: Bundle?) {
    Log.d(TAG, "onCreate(Bundle?) called")

    val provider: ViewModelProvider = ViewModelProviders.of(this)
    val quizViewModel = provider.get(
    Log.d(TAG, "Got a QuizVieModel: $quizViewModel")


private const val TAG = “QuizViewModel”

class QuizViewModel : ViewModel() {

init {
    Log.d(TAG, "ViewModel instance created")

override fun onCleared() {
    Log.d(TAG, "ViewModel instance about to be destroyed")


I have been looking over it to see if I made any spelling errors and unless I am blind, I do not think I have made any. Please let me know what I am doing wrong. I am using the same emulator as the book the Pixel 2 API 28.