From 36ac0c72475e1c1cbade786d78b09f6e96be3921 Mon Sep 17 00:00:00 2001 From: shunf4 Date: Sat, 7 Nov 2020 21:04:17 +0800 Subject: [PATCH] fix: fix "You can't request ViewModel before onCreate call error" --- .../app/notifications/NotificationPermissionActivity.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/readrops/app/notifications/NotificationPermissionActivity.kt b/app/src/main/java/com/readrops/app/notifications/NotificationPermissionActivity.kt index e6c720e5..46230e4e 100644 --- a/app/src/main/java/com/readrops/app/notifications/NotificationPermissionActivity.kt +++ b/app/src/main/java/com/readrops/app/notifications/NotificationPermissionActivity.kt @@ -3,6 +3,7 @@ package com.readrops.app.notifications import android.content.Intent import android.os.Bundle import android.view.MenuItem +import androidx.activity.viewModels import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager @@ -23,7 +24,7 @@ import org.koin.androidx.viewmodel.ext.android.getViewModel class NotificationPermissionActivity : AppCompatActivity() { private lateinit var binding: ActivityNotificationPermissionBinding - private val viewModel = getViewModel() + private lateinit var viewModel: NotificationPermissionViewModel private var adapter: NotificationPermissionListAdapter? = null private var isFirstCheck = true @@ -40,6 +41,7 @@ class NotificationPermissionActivity : AppCompatActivity() { val accountId = intent.getIntExtra(ACCOUNT_ID, 0) + viewModel = getViewModel() viewModel.getAccount(accountId).observe(this, Observer { account -> viewModel.account = account