在 onCreate、onResume 或仅在声明它们时为您的实例变量提供默认值是否更好?在代码中:
声明它们时:
public Class Foo extends Activity{
private String variable1 = "my super var";
private int variable2 = 42;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}
或在 onCreate 期间
public class Foo extends Activity{
private String variable1;
private int variable2;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
variable1 = "my super var";
variable2 = 42;
}
}
或在简历中:
public class Foo extends Activity{
private String variable1;
private int variable2;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
protected void onResume() {
super.onResume();
variable1 = "my super var";
variable2 = 42;
}
}
谢谢你。