-1

I am working on Android applications and getting one problem. I am using Exit Button, so when I am clicking the exit button (which is present in last activity of the application or in Middle but not in First Activity) then the application should close, and when I am restarting the application it should start from the first screen.

But my problem is it's not killing the application and when I am starting again it is starting from the previously paused activities.

I have used System.exit(0) and also used android.os.Process.killProcess(android.os.Process.myPid()).

but those are not working.

halfer
  • 19,824
  • 17
  • 99
  • 186
Ganesh
  • 924
  • 2
  • 12
  • 34
  • Duplicate questions :http://stackoverflow.com/questions/7631289/how-to-destroy-my-application/7683039#7683039 Please research your question before posting. – rDroid Nov 21 '11 at 14:15

3 Answers3

3

in an Activity: this.finish()

in a Service: this.stopSelf()

in a Receiver: return;

Force
  • 6,312
  • 7
  • 54
  • 85
2
  1. You should not. It goes against basic android ideas. Please read about applciation lifecycle.

  2. You could finish individual activity / service with finish()

Konstantin Pribluda
  • 12,329
  • 1
  • 30
  • 35
0

System.exit(0) will do the job. However, it is not at all recommended. Android does some caching, and saving state, so as to relaunch your appp quicker, the next time you launch it.. so you do not want to be messing around with that.

This has been discussed many times, please research your question before posting.

rDroid
  • 4,875
  • 3
  • 25
  • 30