tags:

views:

96

answers:

4

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?

A: 

I hope you have called onDestroy for your activity.

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

Vinay
yes, i have called onDestroy as well as i have finished the activity.
Nishant Shah
onDestroy will destroy the activity not the application
Suresh
I'm confused. Should you *ever* call onDestroy()? I thought it was called exclusively by the system.
Edward Falk
+3  A: 

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
A: 

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
If you have to do this then you're probably doing something wrong
Falmarri
yeah.. you are right.. But i do not find out what is the exact problem.
Nishant Shah
A: 

Hi 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
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
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