在 FragmentActivity 中,super.onCreate 和 setContentView 的顺序并不重要,为什么?
片段活动
//OK
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_waiting_for_confirmation_order);
}
//OK
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_waiting_for_confirmation_order);
super.onCreate(savedInstanceState);
}
但是在 ActionBarActivity 中,它会抛出 NullPointerException。
动作栏活动
//OK
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_waiting_for_confirmation_order);
}
//ERROR
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_waiting_for_confirmation_order); //NullPointerException
super.onCreate(savedInstanceState);
}