I have made an application in android .It is an application related to timer.Now i have tried a lot to put controll on back button of android device that when it is pressed the process should be killed and directly displays main menu...Please help me...Thanking you in advance..!
相关问题
- 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
override
onBackPressed()
in your activity and add your necessary codes thereonBackPressed
you can do like this onclick of back button.
for example : When you moving from A activity to B activity using startActivity(new intent(...)); don't finish or kill A activity, It ll be in stack.
So when you click on back button in B activity you can go back to A activity, which is already in stack.
when you want to go back to main menu call finish() on every activity when your moving to next activity.
for example : When you moving from A activity to B activity using startActivity(new intent(...)); call
finish()
to kill A activity.So when you click on back button in B activity you can go back to Main Menu coz every activity ll be killed.
snippet is here :
Updated : Other way to kill the app using below code on back button pressed. But not recommended
hope this might help you to understand the concept.
well jimmy you can use this code to go to main screen of your device-
finish() method closes current Activity only.
moveTasktoBack will hide your app and You can also kill an application quickly via android.os.Process.killProcess(android.os.Process.myPid()) if you want.
I solved this by override onBackPress() and onStop()
Just clear the activity history so that your application gets closed.And call
finsh();
afterstartActivity();
Happy Coding !