在Android的一个静态变量的生存期 [英] Lifetime of a static variable in Android

查看:197
本文介绍了在Android的一个静态变量的生存期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我宣布,在我的主要活动初始化变量,静态和活动也被毁坏。我仍然可以访问该变量的内容?

when I declare and initialize a variable as static in my main activity and the activity gets destroyed. Can I still access the content of the variable?

例如始终可以访问我存储这个变量的AsyncTask? 我要的是能够同时改变方向时后访问它。

For example to always access a AsyncTask which I store to this variable? What I want is to be able to access to it also after an orientation change.

推荐答案

静态变量与类关联的,他们将生活,只要类是在内存中,并销毁当类被卸载(这很少发生)

Static variables are associated with a class and they will live as long as the class is in the memory,and destroy when class gets unloaded (which very rarely happens).

在Android中你已经看到,当我们关闭所有的应用程序也没有完全关闭,它仍然在最近的应用程序栈,那你可以通过按住在家里键(在大多数设备)看到的。

In Android you have seen that when we close any application it does not close completely, It remains in the recent application stack, That you can see by holding in the home button(On Most Devices).

Android的自身踢出的近期应用程序时,其他的应用需求   内存

Android itself kicked out those recent app when the other app needs memory

这篇关于在Android的一个静态变量的生存期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆