How to disable back button in android while logging out the application?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
Just using this code: If you want backpressed disable, you dont use super.OnBackPressed();
If you want to make sure your android client application is logged out from some server before your Activity gets killed --> log out with a service on its own thread (that's what you're supposed to do anyway).
Disabling the back button won't solve anything for you. You'll still have the same problem when the user receives a phone call for instance. When a phone call is received, your activity has about as much chances of getting killed before it gets a reliable answer back from the network.
That's why you should let a service wait on its own thread for the answer from the network, and then make it try again if it doesn't succeed. The android service is not only much less likely to get killed before it gets an answer back, but should it really get killed before finishing the job, it can always get revived by AlarmManager to try again.
Apart form these two methods from answer above.
You can also override the
dispatchKeyEvent()
(API Level 1, Android 1.0) like this,For me just overriding
onBackPressed()
did not work but explicit pointing which activity it should start worked well:If looking for android api level upto 1.6.
And if looking for a higher api level 2.0 and above this will work great
write this code in your Activity to prevent back button pressed
You can do this simple way Don't call super.onBackPressed()
Note:- Don't do this unless and until you have strong reason to do it.