2012-12-12 27 views
2

//這是我的主要活動如何清除從其他活動得到的bunle值......?

@Override 
    protected void onResume() { 
     super.onResume(); 
     System.out.println("onResume()"); 

     // getting the value form some other class(checking one the activity is started) 
     try { 
      bundle = getIntent().getExtras(); 
      myFlag = bundle.getBoolean("KEY"); 
     } catch (Exception e) { 
      System.out.println(".......Error......."); 
     } 
} 

我提出的myFlag =真,我的問題是,當我不斷改變方向(即重新啓動的活動),我想myFlag =假,但它仍然是正確的...意味着一旦方向改變,我想清除束值。 我嘗試過在onDestroy()方法中使用bundle.clear()和bundle.remove(「KEY」),但不工作。

我已經使用這個..

@Override 
    protected void onDestroy() { 
     super.onDestroy(); 
     System.out.println("onDestroy()"); 
     if(bundle!=null) { 
      bundle.clear(); 
         // i also use the below statement 
         // bundle.remove("KEY"); 
     } 
} 
+0

閱讀本文件:[處理運行時更改] (http://developer.android.com/guide/topics/resources/runtime-changes.html),你會得到線索。 –

回答

2

看到這,你可以有一個想法

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

     if (savedInstanceState != null) { 
      if (savedInstanceState.getBoolean("activity_restarting")) { 
       // activity is restarting... Don't check mFlag..for that do something something here :) 
      } 
     } 

    } 



    @Override 
    protected void onSaveInstanceState(Bundle outState) { 

     super.onSaveInstanceState(outState); 

     outState.putBoolean("activity_restarting", true); 

    } 

我希望你現在能處理

+0

嗨Faizan,尋求你的幫助,現在工作,非常感謝你 – KKC