从后台恢复应用程序后的Android Fragment Transaction

时间:2013-12-11 20:48:29

标签: android android-fragments

据我所知,当从后台恢复经历多个事务的Activity时(按下我们设备的home按钮后),它将再次重新创建所有片段和事务并恢复片段状态。我的问题是

当从片段A移动到片段B时(即添加片段B而不是由片段B替换片段A,因为我需要维护它),我在片段A中暂停了web服务调用。当这个时,不要这样做活动状态恢复了吗?如果没有,我该如何处理呢?

FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.setCustomAnimations(R.anim.activity_slide_in_from_right, R.anim.activity_slide_out_to_left,R.anim.activity_slide_in_from_left, R.anim.activity_slide_out_to_right);
    Channel channel = new Channel();
    channel.setArguments(bundle);
    increaseSubChannelCount();
    String F_TAG = "SUB_CHANNEL_"+subChannelCount;
    Log.i("F_TAG NAME GOING TO BE ADDED ---->",F_TAG);
    String topFragmentName;
    if(getSupportFragmentManager().getBackStackEntryCount() == 0){
        topFragmentName = "ROOT_CHANNEL";
        ((Channel)getSupportFragmentManager().findFragmentByTag(topFragmentName)).pauseChannel();
        Log.i("PAUSED --------->", "ROOT_CHANNEL");
    }
    else{
        topFragmentName = getSupportFragmentManager().getBackStackEntryAt(getSupportFragmentManager().getBackStackEntryCount() - 1).getName();
        ((Channel)getSupportFragmentManager().findFragmentByTag(topFragmentName)).pauseChannel();
        Log.i("PAUSED --------->",topFragmentName);
    }

    transaction.hide(getSupportFragmentManager().findFragmentByTag(topFragmentName));
    transaction.add(R.id.main_content_fragment, channel, F_TAG);
    transaction.addToBackStack(F_TAG);
    transaction.commit();

0 个答案:

没有答案