so i'm new to kotlin and i've come across this bug which i haven't found a fix for. my app freezes and crashes when i press login button. here's my code
class LoginActivity : AppCompatActivity() {
private lateinit var auth: FirebaseAuth
private lateinit var binding: ActivityLoginBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityLoginBinding.inflate(layoutInflater)
setContentView(binding.root)
auth = Firebase.auth
FirebaseAuth.getInstance()
init()
}
private fun init() {
binding.loginButton.setOnClickListener {
loginValidator()
}
binding.loginNotRegisteredText.setOnClickListener {
val intent = Intent(this, RegisterActivity::class.java)
startActivity(intent)
}
}
private fun loginValidator(){
val email = binding.loginEmailEditText.text.toString()
val pass = binding.loginPasswordEditText.text.toString()
if (
email.isEmpty() || pass.isEmpty()
) {
Toast.makeText(this, "Fill all forms!!!", Toast.LENGTH_SHORT).show()
} else {
myCoroutineForLogin()
d("logging in", "Succesfuly logged in")
Toast.makeText(this, "Login successful!!!", Toast.LENGTH_SHORT).show()
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
}
}
private fun myCoroutineForLogin() = runBlocking {
loginWithEmail(
firebaseAuth = FirebaseAuth.getInstance())
}
private suspend fun loginWithEmail(
firebaseAuth: FirebaseAuth,
) = withContext(Dispatchers.IO) {
val email = binding.loginEmailEditText.text.toString()
val pass = binding.loginPasswordEditText.text.toString()
try {
firebaseAuth.signInWithEmailAndPassword(email, pass).await()
} catch (e: Exception) {
}
}
}
this is also my first post on this platform so if there's something else you might need, mention it please. I should also probably mention that i do get idtoken so it does connects to firebase
EDIT1: only thing i get in logcat debug. tried logging in twice.
2021-11-14 16:41:24.661 11485-11622/com.example.todolist I/FA: App measurement initialized, version: 44007
2021-11-14 16:41:24.662 11485-11622/com.example.todolist I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
2021-11-14 16:41:24.662 11485-11622/com.example.todolist I/FA: To enable faster debug mode event logging run:
adb shell setprop debug.firebase.analytics.app com.example.todolist
2021-11-14 16:41:24.885 11485-11622/com.example.todolist I/FA: Tag Manager is not found and thus will not be used
2021-11-14 16:41:25.371 11485-11506/com.example.todolist W/System: A resource failed to call close.
2021-11-14 16:41:28.631 11485-11485/com.example.todolist I/AssistStructure: Flattened final assist data: 1692 bytes, containing 1 windows, 8 views
2021-11-14 16:41:34.021 11485-11605/com.example.todolist W/System: Ignoring header X-Firebase-Locale because its value was null.
2021-11-14 16:41:34.416 11485-11605/com.example.todolist W/System: Ignoring header X-Firebase-Locale because its value was null.
2021-11-14 16:41:34.627 11485-11605/com.example.todolist D/FirebaseAuth: Notifying id token listeners about user ( lC3oIoM9vdhJ9920PxEWdSXp8Rt2 ).
2021-11-14 16:41:59.876 11485-11498/com.example.todolist I/xample.todolis: Thread[4,tid=11498,WaitingInMainSignalCatcherLoop,Thread*=0xe8482a10,peer=0x13380268,"Signal Catcher"]: reacting to signal 3
2021-11-14 16:41:59.918 11485-11498/com.example.todolist I/xample.todolis: Wrote stack traces to tombstoned
there were no stack traces, but after spam clicking on avd it added that "stack traces were written to tombstoned" tried to look up what is tombstoned or where can i find it but couldnt find anything helpful about it. im going to try testing on real mobile phone now and i'll update if anything changes
EDIT2: Tried doing auth without coroutines as suggested in comments and it does work. still, would like to get an idea why it might not be working with coroutines or what i'm doing wrong. here's whole project: https://bitbucket.org/xRawAnger/todolist/src/testing1/