how to use variable in onSaveInstanceState

This question already has an answer here:

  • Saving Android Activity state using Save Instance State 25 answers

  • Cyren... 1) I see no reason to call super.onRestoreInstanceState in onCreate. It WOULD make sense to make that call in the method

    public void onRestoreInstanceState(Bundle saved) {
        super.onRestoreInstanceState(saved);
    

    2) The declaration:

       int resultCode = savedInstanceState.getInt("resultCode");
    

    is "hiding" the variable:

    int resultCode;
    

    declared earlier. So there are two version of the variable resultCode with different scopes. Perhaps you mean to code:

    int resultCode;
    
    stuff here
    
        resultCode = savedInstanceState.getInt("resultCode");
    

    Hope that helps, JAL

    链接地址: http://www.djcxy.com/p/26182.html

    上一篇: 在Android中保存活动移动到其他活动时

    下一篇: 如何在onSaveInstanceState中使用变量