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:
MainActivity.kt:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Log.d(TAG, "onCreate(Bundle?) called")
setContentView(R.layout.activity_main)
val provider: ViewModelProvider = ViewModelProviders.of(this)
val quizViewModel = provider.get(QuizViewModel::class.java)
Log.d(TAG, "Got a QuizVieModel: $quizViewModel")
QuizViewModel.kt
private const val TAG = “QuizViewModel”
class QuizViewModel : ViewModel() {
init {
Log.d(TAG, "ViewModel instance created")
}
override fun onCleared() {
super.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.