title: android: application crash when i hit back button (activitygroup + TabWidget)
body: <p>every one!</p>
  
  <p>One year ago, I have developed an application with the combination "ActivityGroup + TabWidget", it works well on android os 2.3+. But I tested it on os 4.0, and I found it crash sometimes. 
  - If I open application, I do nothing, and i hit "back", it works well.
  - If I open application, navigate in the application (click on list item, see detail item then go back), and then when I am back to the "root" page of a tab, i click "back", it crash. (It should close the application normally) --------in this case, the activitygroup start new activity and recieve the back keyevent
  - If I open application, navigate in the application like above, but juste see the views not started by activitygroup, but by the root activity in the group. Il works well. </p>
  
  <p>There are some code in my ActivityGroup</p>
  
  <pre><code>public void startActivity(Intent intent) {
  // Start the root activity withing the group and get its view
      View view = getLocalActivityManager().startActivity(id, intent)
                                          .getDecorView();
      // Replace the view of this ActivityGroup
      replaceView(view);
  }
  
  public void back() {
      if(history.size() &gt; 1) {  //history = new ArrayList&lt;View&gt;(); global variable
          history.remove(history.size()-1);
          setContentView(history.get(history.size()-1));
  
          mIds.pop();
      }else {
          finish();    // I tried to commment it too, but no lucks
      }
  }
  
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event)  {
      if (keyCode == KeyEvent.KEYCODE_BACK) {
          back();
  
          return true;
      }
  
      return super.onKeyDown(keyCode, event);
  }
  </code></pre>
  
  <p>And there's the error stack:</p>
  
  <pre><code>05-18 18:47:47.687: E/AndroidRuntime(6828): FATAL EXCEPTION: main
  05-18 18:47:47.687: E/AndroidRuntime(6828): java.lang.IllegalStateException: Can not                 perform this action after onSaveInstanceState
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at android.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1213)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at     android.app.FragmentManagerImpl.popBackStackImmediate(FragmentManager.java:442)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at android.app.Activity.onBackPressed(Activity.java:2121)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at android.app.Activity.onKeyUp(Activity.java:2099)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at android.view.KeyEvent.dispatch(KeyEvent.java:2557)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at android.app.Activity.dispatchKeyEvent(Activity.java:2329)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1806)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1248)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1248)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1248)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1859)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1361)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at android.app.Activity.dispatchKeyEvent(Activity.java:2324)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1806)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1248)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1248)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1248)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at android.widget.TabHost.dispatchKeyEvent(TabHost.java:298)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1248)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1248)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1248)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1859)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1361)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at android.app.Activity.dispatchKeyEvent(Activity.java:2324)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1806)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3300)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at android.view.ViewRootImpl.handleFinishedEvent(ViewRootImpl.java:3273)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2436)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at android.os.Handler.dispatchMessage(Handler.java:99)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at android.os.Looper.loop(Looper.java:137)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at android.app.ActivityThread.main(ActivityThread.java:4340)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at java.lang.reflect.Method.invokeNative(Native Method)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at java.lang.reflect.Method.invoke(Method.java:511)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
  05-18 18:47:47.687: E/AndroidRuntime(6828):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>I didn't use Fragment, because it wasn't published by android sdk when i developped this application. </p>
  
  <p>Any ideas? Every idea will be appreciated!!<br>
  Thanks!</p>