5

I have a litle doubt.

I have an activity that have 3 fragment inside. I need to restart the state of one of these fragments. Restart only one.

enter image description here

tshepang
  • 12,111
  • 21
  • 91
  • 136
Ricardo Filipe
  • 435
  • 4
  • 8
  • 24
  • Please provide some more information: about fragment stack, and what do you meen under 'restart fragment state'? – Evos Dec 21 '12 at 11:30
  • Hello Evos. Thanks for your reply. I have a fragment with information contacts. And in a certain moment i need to restart the fragment. This is, put the fragment in the initial state – Ricardo Filipe Dec 21 '12 at 11:36
  • If you don't need to save fragments backstack you simple neeed to commit new contacts fragment and and don't add this transaction to back stack. – Evos Dec 21 '12 at 11:40

1 Answers1

8

Old, but may be useful to someone else. To refresh the fragment, you need to detach the fragment and reattach it

Fragment frg = null;
frg = getFragmentManager().findFragmentByTag("Your_Fragment_TAG");
final FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.detach(frg);
ft.attach(frg);
ft.commit();

Your_Fragment_TAG is the name you gave your fragment when you created it

Manoj Kumar
  • 1,510
  • 3
  • 20
  • 40
  • If you replace what's in the fragment container with the new fragment you wish to load then will that accomplish same thing? I have a game with an activity containing a Frag for game(gameFrag) and dialog for endgame page. In order to restart the game fragment is it best to replace frag container with game frag or better to detach and attach and why? Many thx. – cjayem13 Aug 20 '14 at 19:11
  • detach and attach. less lag. less usage of hw resources. crucial in ur case. – Manoj Kumar Oct 29 '14 at 14:00