// 1) Remove userManager field
@Inject
lateinit var userManager: UserManager
@Inject
lateinit var mainViewModel: MainViewModel
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings) <<<<<<<<<<<<< Not Supposed to be here <<<<<<<<<<
// 2) Grab userManager from appComponent to check if the user is logged in or not
val userManager = (application as MyApplication).appComponent.userManager()
if (!userManager.isUserLoggedIn()) { ... }
else {
setContentView(R.layout.activity_main)
// 3) If the MainActivity needs to be displayed, we get the UserComponent
// from the application graph and gets this Activity injected
userManager.userComponent!!.inject(this)
setupViews()
}
}
...
class MainActivity : AppCompatActivity() {
}