addToBackStack不能正常工作

时间:2015-11-21 18:51:58

标签: android fragment

    public void showErrorFragment(String message, Fragment fragment1) {

    String backStateName = fragment1.getClass().getName();
    Log.d(TAG, "showErrorFragment");
    mFragment = ErrorFragment.newInstance(message);
    fragmentManager.beginTransaction()
                .replace(R.id.fragmentContainer, mFragment, ErrorFragment.TAG)
                .addToBackStack(backStateName)
                .commit();
}

当我在ErrorFragment中调用getFragmentManager()。popBackStackImmediate()时, fragment1未显示。

2 个答案:

答案 0 :(得分:1)

如果你使用addToBackStack与字符串arugment你也应该使用popBaskStackImmediate字符串参数

答案 1 :(得分:0)

如果fragment1中的R.id.fragmentContainer在替换之前没有#include <stdio.h> #include <stdlib.h> #include <string.h> #define ROWS 8 #define COLS 8 #define NUMBER_OF_QUEEN 8 typedef struct { int col; int row; } queen_t; void getAllPossibleQueenLand(queen_t queens[] , int*count); int canPlaceQueen(queen_t queen1 , queen_t queen2); int checkAllTheQueenTillNow(queen_t queens[] , int length); void main() { int count = 0; int numberOfIteration = 0; queen_t queens[NUMBER_OF_QUEEN]; queens[0].col = 0; while(queens[0].col != COLS){ getAllPossibleQueenLand(queens , &count , &numberOfIteration); } printf("number of iteration is : %d \n" , count); system("pause"); } void getAllPossibleQueenLand(queen_t queens[] , int *count , int *numberOfIteration) { if(queens[(*numberOfIteration)].row != (*numberOfIteration)) { queens[(*numberOfIteration)].row = (*numberOfIteration); queens[(*numberOfIteration)].col = 0; } if(queens[0].col == COLS) { return; } else if(queens[(*numberOfIteration)].col == COLS) { queens[(*numberOfIteration)].col = 0; queens[(*numberOfIteration) - 1].col++; (*numberOfIteration)--; getAllPossibleQueenLand(queens , count , numberOfIteration); return; } else if(checkAllTheQueenTillNow(queens , (*numberOfIteration) + 1) == 0 ) { queens[(*numberOfIteration)].col++; getAllPossibleQueenLand(queens , count , numberOfIteration); return; } else if( (*numberOfIteration) != NUMBER_OF_QUEEN - 1) { (*numberOfIteration)++; getAllPossibleQueenLand(queens , count , numberOfIteration); } else{ //found another possible place .. did the bonuse!! (*count)++; queens[(*numberOfIteration)].col = 0; queens[(*numberOfIteration)-1].col++; (*numberOfIteration)--; } ,则弹出后筹码不会显示它。这不是它的工作方式。