删除并提交片段但它仍然在getSupportFragment Manager中

时间:2016-05-14 00:41:48

标签: android fragment commit

有关为什么片段没有被删除的任何想法?这是一个使用retaininstance(true)从'AsyncTask'片段调用的接口方法。在删除测试中,mTaskFragment不等于null,因此打印日志行。

@Override
public void onPostExecute(boolean success, String result, String message) {

    Log.d(TAG, "onPostExecute()");


    //Remove the Fragment if its still there
    FragmentManager fm = getSupportFragmentManager();
    mTaskFragment = (MyAsyncTaskFragment) fm.findFragmentByTag(TAG_TASK_FRAGMENT);
    if (mTaskFragment != null) {
        fm.beginTransaction().remove(mTaskFragment).commit();
    }
    mTaskFragment = null;


    //Test of remove
    mTaskFragment = (MyAsyncTaskFragment) fm.findFragmentByTag(TAG_TASK_FRAGMENT);
    if (mTaskFragment != null) {
        Log.d(TAG, "mTaskFragment is not null");
    }

0 个答案:

没有答案