2

这是我的 TabGroupActivity 的代码。在这里,在任何特定选项卡上 Tab B-> 然后它将启动其子活动 Class C -> 然后单击任何按钮它将再次调用子活动 Class D

现在,每当我按下返回按钮时,从 D 类开始,它会再次重新加载子活动类 C。从 C 类开始,当我按下返回按钮时,它将再次重新加载子活动。

请帮我解决这个问题。我不想重新加载以前的活动。

      public class TabGroupActivity extends ActivityGroup {

private ArrayList<String> mIdList;
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);

}
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);     
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    if (mIdList == null) mIdList = new ArrayList<String>();
}

/**
 * This is called when a child activity of this one calls its finish method. 
 * This implementation calls {@link LocalActivityManager#destroyActivity} on the child activity
 * and starts the previous activity.
 * If the last child activity just called finish(),this activity (the parent),
 * calls finish to finish the entire group.
 */
      @Override
       public void finishFromChild(Activity child) {
  LocalActivityManager manager = getLocalActivityManager();
  Log.i("Stack,finishFromChild", ""+mIdList);
  int index = mIdList.size()-1;

  if (index < 1) {
      finish();
      return;
  }

  manager.destroyActivity(mIdList.get(index), true);
  mIdList.remove(index); index--;
  String lastId = mIdList.get(index);
  Intent lastIntent = manager.getActivity(lastId).getIntent();
  lastIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
  Window newWindow = manager.startActivity(lastId, lastIntent);


  setContentView(newWindow.getDecorView());
   }

      /**
     * Starts an Activity as a child Activity to this.
      * @param Id Unique identifier of the activity to be started.
       * @param intent The Intent describing the activity to be started.
     * @throws android.content.ActivityNotFoundException.
       */
     public void startChildActivity(String Id, Intent intent) {     
  Window window = getLocalActivityManager().startActivity(Id,intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP));
  if (window != null) {
      mIdList.add(Id);
      setContentView(window.getDecorView()); 
  }    
   }

    /**
     * The primary purpose is to prevent systems before          android.os.Build.VERSION_CODES.ECLAIR
     * from calling their default KeyEvent.KEYCODE_BACK during onKeyDown.
    */

     /**
      * If a Child Activity handles KeyEvent.KEYCODE_BACK.
      * Simply override and add this method.
        */
     @Override
     public void  onBackPressed  () {
        int length = mIdList.size();
        if ( length > 1) {
        Log.i("Stack,onback", ""+mIdList);

        Activity current = getLocalActivityManager().getActivity(mIdList.get(length-1));
        Log.i("Activity in current",""+current);
         current.finish();

     }  
     else
     {
        if(length==1)
        {
          Activity current = getLocalActivityManager().getActivity(mIdList.get(length-1));
          Log.i("Activity in current",""+current);
          current.finish();
      }
  }
  }
4

0 回答 0