开发者

How to erase static variables in Android

开发者 https://www.devze.com 2023-01-20 18:55 出处:网络
I read this Article on StackOverflow. According to this, static variables will be erased, if the class is unloaded

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.


How about setting the static variable to null?


You question isn't all clear, so I'll give you two options:

A
If you want to terminate your application programmatically, you can call finish() anywhere from within your code.

B
If you simply want to kill your application "manually" on your device, you to the following:

  • Click Menu
  • Click Settings
  • Click Applications
  • Click Manage applications
  • Find your app in the list, select it and click Force stop

Edit:
I guess there also is a third option, but this might have to be done together with calling finish() to be sure it happens:

In your activity you could also override the onDestroy() method. Inside your implementation of onDestroy() you can do any clean-up you need, such as resetting your static variables (e.g. to null).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号