快速的问题,但我在文档中找不到答案。
Android 应用程序中静态字段的生命周期是多少? 什么时候初始化,什么时候销毁?最终属性是否会修改其生命周期?私人/公共呢?只要应用程序实例还活着,它们就存在吗?
举两个例子:
public class DemoClass {
static int one = 1;
static int three = DemoActivity.two + one;
}
public class DemoActivity extends Activity {
public static int two = DemoClass.one + DemoClass.one;
private static final int four;
public static int five;
public void onCreate(Bundle b) {
four = two + two;
five = DemoClass.three + DemoClass.one + DemoClass.one;
}
}
编辑:还有静态字典呢?
例如,
public class AnotherDemoActivity extends Activity {
public static ArrayList<String> strings = new ArrayList<String>();
@Override public void onCreate(Bundle b) {
strings.add("test");
strings.add(new String("another test");
strings.add(new DemoClass());
}
“字符串”元素会存在多久?