views:

49

answers:

2

I read this Article on StackOverflow. According to this, static variables will be erased, if

  1. the class is unloaded
  2. the JVM shuts down
  3. the process dies

But how to destroy / to kill my application (application process) and so to erase all static variables programmatically from my application?!

Thank you,

Mur

UPD

These static variables will be filled by reading some data from server. Here is a test workflow:

  1. I start application -> static variables will be filled
  2. I go to home activity pressing back button -> finish() will be called
  3. I turn off internet connection (I'm sure there is no connection)
  4. Then I start application againg
  5. Static variables are still filled

Some Ideas?

Is there possibility to close all activities of an aplication? Will be application 'closed' in that case?

Ps. Yes, I know, it's not the best way to use static variables, but i'm not the the author of that application, I'm just fixing bugs and put some new features to it.

A: 

How about setting the static variable to null?

Scythe
i tried to do that, but they are (static variables) still there until i don't kill application process in ddms
Mur Votema
I'm sure that there's a way to manually call the garbage collector in this case. Never tried to do it tho, but the solution's got to be somewhere there.
Scythe
A: 
Nailuj
finish() doesn't help :(
Mur Votema
See updated answer on using `onDestroy()`.
Nailuj
yes, also thought about that ... that's not nice, but that's at least a solution
Mur Votema
@Mur: the *intention* of `onDestroy()` is that you should use this as a place to clean up when your application closes, such as clearing variables, references etc. This is according to the Activity Lifecycle, so as such it doesn't get much nicer than this. An also, what makes this "not nice" isn't the use of `onDestroy()`, but rather the weird use of static variables in your app. So I suggest either going for this or see if you can re-design your app ;)
Nailuj
application will be re-designed but not now. now it must work and there is no time for experiments :(
Mur Votema