2017-03-03 5 views
1

私は "savedInstanceState"を使用する理由 次の問題が発生しますか? プログラムが最初に受信したときに、受信メッセージを受信しました。restore savedStstStateが格納されたものと一致しません

しかし、私はビデオギャラリーのビデオを選択します。 'savedInstanceState'にあり 保存する "テスト" しかし回復が と等しい条件 'test' 実行できません? 'savedInstanceState.getString( "キー")' の量 は '試験' である一方、

'Else if (savedInstanceState.getString (" key ")! ="test")' 

で そして注文は、実行されましたか?

protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     if (savedInstanceState != null) { 

      if (savedInstanceState.getString("key")=="test"){ 

       TextView txtarr_1=(TextView) findViewById(R.id.test_array_1); 
       txtarr_1.setText("if(savedInstanceState.getString(key)==test){" + savedInstanceState.getString("key")+"}"); 

      } 
      else if (savedInstanceState.getString("key")!="test") { 
       TextView txtarr_3=(TextView) findViewById(R.id.test_array_3); 
       txtarr_3.setText(savedInstanceState.getString("key")); 

      }  

     }else{ 
     TextView txtarr_5=(TextView) findViewById(R.id.test_array_5); 
     txtarr_5.setText("elseif (savedInstanceState != null)"); 
     }} 

    @Override 
    public void onSaveInstanceState(Bundle savedInstanceState) { 
     savedInstanceState.putString("key", "test"); 

     super.onSaveInstanceState(savedInstanceState); 
    } 

答えて

0

私は文字列を格納代わりに::ようにコードを変更する - >この場合、整数を格納し

@SuppressLint("NewApi") 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_main); 

    if (savedInstanceState != null) { 

    int val=savedInstanceState.getInt("key"); 

      if (val==123){ 

    TextView txtarr_1=(TextView) findViewById(R.id.test_array_1); 

txtarr_1.setText("if == 123{" + savedInstanceState.getInt("key")+"}"); 


    } 
    else if (val!=123) { 
    TextView txtarr_3=(TextView) findViewById(R.id.test_array_3); 
txtarr_3.setText(savedInstanceState.getString("key")); 
    }  

    }else{ 
TextView txtarr_5=(TextView) findViewById(R.id.test_array_5); 
txtarr_5.setText("elseif (savedInstanceState != null)"); 
    }} 

@Override 
public void onSaveInstanceState(Bundle savedInstanceState) { 
savedInstanceState.putInt("key", putInt); 

    super.onSaveInstanceState(savedInstanceState); 
} 

問題が平均だ を解決することができます。 は、私は123と注文を保存検出されました123に等しいが を行ったが、私は123と等しくない文字列の 実行順序を形成するために123を保存する場合は保存されたフォームへの呼び出しで新しいアクティビティを

を実行しました210と復元時に格納された値が異なる しかし、私はまったく同じテキストを表示する?????? なぜ?????

0

は私が==

if (savedInstanceState != null) { 
    String str =savedInstanceState.getString("key"); 
    if (str.equals("test")){ 

     TextView txtarr_1=(TextView) findViewById(R.id.test_array_1); 
     txtarr_1.setText("if == test{" + str+"}"); 

    } 
    else if (!str.equals("test")){ 
     TextView txtarr_3=(TextView) findViewById(R.id.test_array_3); 
     txtarr_3.setText("if != test{" + str+"}"); 

    }  

}else{ 
TextView txtarr_5=(TextView) findViewById(R.id.test_array_5); 
txtarr_5.setText("elseif (savedInstanceState != null)"); 
} 
を、等しく使用することはできませんIF内の文字列のために私のミス

を見つけました

関連する問題