0

I have an android app, and when the Home key is pressed I want it to terminate. Period. I dont want it hanging around running in the background. I just want it terminated. What's the best or prferred method to do this?

Jack
  • 241
  • 4
  • 12
  • Try **[this](http://stackoverflow.com/questions/5842272/android-how-to-exit-an-app-when-user-press-the-home-button)**. – Cat Jun 09 '12 at 18:58
  • 3
    possible duplicate of [Quitting an application - is that frowned upon?](http://stackoverflow.com/questions/2033914/quitting-an-application-is-that-frowned-upon) – CommonsWare Jun 09 '12 at 19:08

2 Answers2

7

No you don't.

  • Trying to "kill" your app is an Android antipattern.

  • Trying to catch the home key is also an Android antipattern.

There is a vast amount of material substantiating these points. If you think you do want your application killed, you're just plain wrong.

Kristopher Micinski
  • 7,572
  • 3
  • 29
  • 34
0

You can use finish(); to terminate an activity.

Grant
  • 4,413
  • 18
  • 56
  • 82
  • 1
    But not if you're deep in the Activity stack, you would have to call it an appropriate number of times to get back to the "start" of the app. – Kristopher Micinski Jun 09 '12 at 20:25