I'd like to destroy my application when the user touches the home button of Android device and begin the MainActivity when the user touches the "back" button of Android. Does any ones knows how to do that?
相关问题
- 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
You can do this by calling the finish() and finishActivity() methods. checkout the details on API guide Shutting down an Activity. From where to call these methods is based on how your application is implemented, but I guess you can do this from the current focused activity by listening to KeyEvent and filtering on Home button key event.
However you need to consider that once you have killed your activities pressing the back button will not get you back to your application activity since killing the activities will wipe them out of memory stack.
Also check out the Activity life cycle diagram and detailed description given on Android Developers site.
But it's best not to use it. Android isn't designed for this purpose.
Close application and launch home screen on Android
You can close an
Activity
by callingfinish()
, but you'll have to do that for eachActivity
that is open. To have this happen upon pushing the HOME button, you'll have to register aKeyEvent
. I'm not too clear on how to do this, but you can find documentation here.For close app on Back
And You can't get click event of Home Button so you want to code onStop method.
call
finish()
in youronStop()
method. Or useandroid:noHistory="true"
in your manifest.