'Unresolvered reference: when I call the method of an instance from another activity
I would like to call the method of an instance of AuthActivity from MainActivity. However, I get an error. AuthActivity contains a variable that lets you know if the user has already authenticated from this activity!
Unresolvered reference: checkIfUserAlreadyLogged()
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
FirebaseApp.initializeApp(applicationContext)
setContentView(R.layout.activity_main)
if (AuthActivity.checkIfUserAlreadyLogged()) {
return this.displayAuthWithFragment(AuthActivity.HOME_FRAGMENT)
}
}
}
Here is my AuthActivity class:
package com.ksainthi.inance
import androidx.appcompat.app.AppCompatActivity
import androidx.activity.result.contract.ActivityResultContracts
import androidx.fragment.app.Fragment
import com.google.firebase.auth.FirebaseAuth
class AuthActivity : AppCompatActivity() {
private val firebaseAuth: FirebaseAuth by lazy {
FirebaseAuth.getInstance()
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_auth)
}
fun checkIfUserAlreadyLogged(): Boolean {
if (this.firebaseAuth.currentUser != null) {
return true
}
return false
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|