有关为什么片段没有被删除的任何想法?这是一个使用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");
}