【发布时间】:2019-11-29 15:05:23
【问题描述】:
当我在 Android 应用上创建 JOIN Action 和 LOGIN Action 时, 发生了问题。 在 LOGIN Action 中使用 MVP 模式。 但是登录的结果并不是我想要的。 我给你看代码。
class LoginModel {
var TAG = "LoginModel"
private var ID: String
private var PW: String
var resultTxt: String = ""
var auth: FirebaseAuth = FirebaseAuth.getInstance()
constructor(ID: String, PW: String) {
this.ID = ID
this.PW = PW
}
fun login(ID: String, PW: String) : String{
this.ID = ID
this.PW = PW
auth.signInWithEmailAndPassword(ID, PW)
.addOnCompleteListener { task ->
//
if (task.isSuccessful) {
val user = auth.currentUser
resultTxt = "Login Success"
} else {
resultTxt = "Login Failed"
}
}
return resultTxt
// I'd like to process the results based on the return.
// But it doesn't return the way I want it.
// I know it's related to asynchronous processing.
// So where should I put the callback function, and how should I write
// it?
}
}
【问题讨论】:
-
查看我的回答,希望对您有所帮助
-
请考虑给这个问题并回答一个upvote,这是未来如何为人们进行回调的基本示例:D stackoverflow.com/questions/57330766/…
标签: android firebase kotlin callback firebase-authentication