Android:如何忽略或禁用savedInstanceState?

时间:2011-06-01 08:30:27

标签: java android instance state

我想忽略或禁用savedInstanceState,以便在进入下一个活动时不会保存当前活动的状态。

public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);

4 个答案:

答案 0 :(得分:14)

就是这样:

public void onCreate(Bundle savedInstanceState){
    super.onCreate(null);

答案 1 :(得分:7)

或者这个:

@Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.clear();
    }

答案 2 :(得分:5)

在活动xml文件中写下此行:

    android:saveEnabled="false"

答案 3 :(得分:0)

只需覆盖onRestoreInstanceState而不调用超级版本

@Override
    protected void onRestoreInstanceState(Bundle outState) {
        //Just leave it empty
    }