En gros :
quand tu rajoutes tes fragments dans ta backstack avec les FragmentTransaction lors de l'appel de la méthode add ou replace tu peux rajouter en fin de paramètre le tag associé à cet action.
Ce tag qui est un string te permet plus tard de pouvoir retrouver un fragment présent dans ta backstack avec le tag recherché.
Du style ici je rajoute mon fragment dynamique mainFragment à qui j'associé le tag mainFragmentTag qui est un string que j'aurais défini en static.
fTransaction.add(R.id.firstpane, mainFragment, mainFragmentTag);
Si un jour j'ai besoin de le retrouver alors je n'aurais plus qu'à appelé la méthode findFragmentByTag avec le tag mainFragmentTag
getFragmentManager().findFragmentByTag(mainFragmentTag);
Soit il trouve le fragment dans la backstack et me le retourne soit il n'y est pas présent car je l'ai supprimé entre temps et là j'ai null.
Partager