3

I have developed an application which is working fine.

In that i have used some static variables and also set Application level variables. My problem is that even after setting finish() on each activity, application is showing in Running mode.

After closing the application, when i start the application after sometime, it will set the last changes.

How can i destroy my application?

Nishant Shah
  • 3,442
  • 5
  • 25
  • 34

5 Answers5

12

I think the correct answer is "you shouldn't".

It doesn't matter if your app is still running after the user stops using it. Android will kill it when/if it needs to.

Your app most likely shouldn't even have an exit button.

oli
  • 4,894
  • 1
  • 17
  • 11
3

I have checked that application does not release the resources. So, what i have done is :

Process.killProcess(Process.myPid());

It will kill the application. It helps me a lot.

Nishant Shah
  • 3,442
  • 5
  • 25
  • 34
3

call

System.exit(0);

from within

OnDestroy()

And yes, you shouldn't.

Adriano Carneiro
  • 57,693
  • 12
  • 90
  • 123
Lake
  • 39
  • 1
0

I hope you have called onDestroy for your activity.

Secondly, are you saving your preference some where else??

Vinay
  • 2,395
  • 3
  • 30
  • 35
0

Please go through these methods used for the destroying the activities

setResult() finish() and onActivityresult()

After calling setResult() call finish() for the activity that you want to finish & then in it's parent activity override onActivityResult() in this you can finished your application.

The solution given by oli is right android will destroy your application running. But I want add, only if it is lacking in system resources.

For more help please go through following link.

http://developer.android.com/reference/android/app/Activity.html

Ashay
  • 675
  • 4
  • 13
  • 1
    I suspect Nishant's problem is that he's storing data global to the application (perhaps in a static value in the Activity) and not in the activity instance. This data will persist even after every instance of every activity has gone away, and will only be released after the system kills the entire process. (I used to (wrongly) use this technique to persist a large dataset across orientation changes.) The proper solution is to not do this. – Edward Falk Aug 06 '10 at 15:37
  • Hey Edward, I have used this link to store values globally : http://stackoverflow.com/questions/708012/android-how-to-declare-global-variables. I have some static int and string variables. – Nishant Shah Aug 07 '10 at 04:30