how to unable back in android using firebase auth android

问题: i had a problem when I'm trying to make logout button, it's success when i press the logout button but when i press back button, the screen move to previous activity, how t...

问题:

i had a problem when I'm trying to make logout button, it's success when i press the logout button but when i press back button, the screen move to previous activity, how to make to unable the back button without unable the onbackpressed function


回答1:

Use intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); whenever you start new activity on logout button click.

This will clear all activities from back stack , so when you press back button app will not open previous activity.


回答2:

If you want to close the application after logout, then call finishAffinity() in onBackPressed() method as

override fun onBackPressed() {
    finishAffinity()
}

OR, If you want to navigate to other activity after logout, then

override fun onBackPressed() {
    // Write your code here
    super.onBackPressed()
}
  • 发表于 2019-02-19 23:08
  • 阅读 ( 186 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除