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()
}