0

In made the android app. I installed it in my mobile. When I press back button on my mobile it comes out of the app. But it is running in the background. So, how can I finish the activity completely? I wrote the code onkeydown event also. Even it is running in background.

AlexVogel
  • 10,601
  • 10
  • 61
  • 71
VK.Dev
  • 801
  • 4
  • 11
  • 24

6 Answers6

1

You should override the onStop() method on your activity and in call the finish() method from it. Don't forget to call super.onStop() at the beginning of the onStop() method. As far as I know it's not running on the background, android saves the state of the activity and when it comes back, it restores your activity with the same state it was.

artex
  • 1,776
  • 2
  • 11
  • 16
mendes
  • 21
  • 5
  • Try this! Try LocationManager.removeUpdates() in onStop – Aman Alam Jan 27 '11 at 06:40
  • 1
    Also read the http://developer.android.com/reference/android/app/Activity.html#ProcessLifecycle which describes why you shouldn't bother. NB: Your finished application will still be seen in the "process list" (which you get when holding down the home button). – thoredge Jan 27 '11 at 08:15
0

Hi see the following link in that also same question is available.Finish the android application completely

Community
  • 1
  • 1
Pinki
  • 21,723
  • 16
  • 55
  • 88
0

I will keep running in the background. Android decides when to kill your activity.

By the way, How do you ensure that it is running and "working" (is not frozen) ??

Aman Alam
  • 11,231
  • 7
  • 46
  • 81
  • my app get the current location.It shows the status of gps on toast.When i enable the GPS it shows GPS enabled on toast.So when i press back button it comes out and then when i disable the GPS.It shows GPS Disabled on toast.That is my problem. – VK.Dev Jan 27 '11 at 06:25
  • It maybe because your device says so, but not the app!! Just a wild guess. which device you have? – Aman Alam Jan 27 '11 at 06:34
  • My device is not saying that.My app says that bcoz i wrote the code for showing status and my device is Samsung G3. – VK.Dev Jan 27 '11 at 06:37
  • 2
    Then stop watching for GPS location when your activity's onStop() method is called. – hackbod Jan 27 '11 at 07:51
  • @Dev.Android: As @hackbod says, you need to properly manage your activity lifecycle and respond to onStop(), but also onPause(), and onResume() – RivieraKid Jan 27 '11 at 09:34
0

In your onKeyDown() handler you should add this:

finish();

This causes the activity to be closed.

Graham Borland
  • 60,055
  • 21
  • 138
  • 179
Parag Chauhan
  • 35,760
  • 13
  • 86
  • 95
0

You can call Activity.finish() to kill of an activity completely.

Be aware that this it not something your should normally do, as Android really want to manage the activity life cycle for you, as mentioned by Sheikh Aman.

rogerkk
  • 5,494
  • 5
  • 37
  • 53
-1

Call this:

android.os.Process.killProcess(android.os.Process.myPid());

It's odd, but only this call guarantees that you will kill your application. Due to specific Android life-cycling neither finish() nor any other methods doesn't kill application.

Barmaley
  • 16,638
  • 18
  • 73
  • 146