简体   繁体   中英

How to complete the application when pressed buttons Home i Back?

How to complete the application when pressed buttons Home and Back? Provided that in my memory holds many pictures. When pressed on the Back button - application restarts... When pressed on the Home button - quit application, but when it restart - does not start Splashstsreen.

Hard to see without code but it sounds like your activity is resuming rather then starting from scratch (as it should behave). It sounds like it's behaving correctly in that case. If you insist in wanting your application to truly quit after the back button is clicked perhaps you can override onBackPressed() then have your Activity call its finish() method.

I don't think it's good programming practice to fiddle and interfering with the activities lifecycle. It's the OS responsibility to manage the lifecycle, including pause and finish activities. Instead you should use other methods to handle your problem with not showing splash screen, these methods are onResume and maybe also onStart(). Also you should get familiar with the activity lifecycle(link submitted by @ss1271).

Press Home will let the activity to enter onPause() . however, if you insist to quit the application when press HOME, which is obviously not a good practise, you can do like this:

  1. Override onPause() and onBackPressed()
  2. add finish(); to these methods.

I am sure by adding finish(); to onBackPressed() will quit the app when Back button pressed, but I haven't tried on Home.

Please refer to Activity Lifecycle for more info.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM