Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh fragment is not working any more?

I lost some hours today because my code was not working any more. The code to reload the view of a fragment was not working anymore after updating to the new version of Support Library 25.1.0:

This is my code :

FragmentManager manager = getActivity().getSupportFragmentManager();
FragmentTransaction fragmentTransaction = manager.beginTransaction();
fragmentTransaction.detach(fragment);
fragmentTransaction.attach(fragment);
fragmentTransaction.commit();

I have tried to debug putting some breakpoints on

public void onPause()
public void onStop()
public void onAttach(Context context)
public void onDetach()  
public void onDestroyView()
public void onDestroy()

but the application is not entering into any of that function and nothing happened on the screen.

If I call detach alone, without attach, the application enter in onPause and onStop and the view leave the screen.

like image 231
Brahim Bouaboud Avatar asked Dec 21 '16 19:12

Brahim Bouaboud


1 Answers

Faced a similar issue after updating androidx.navigation from 2.3.1 to 2.3.2.

parentFragmentManager.beginTransaction().detach(this).attach(this).commit()

has stopped reload the view of a fragment. Everything that I found here did not help, but I noticed that separately the detach and attach operations are being performed successfully, I decided to spread their execution to different FragmentTransaction entities:

parentFragmentManager.beginTransaction().detach(this).commit ()
parentFragmentManager.beginTransaction().attach(this).commit ()

and it worked. Hope this saves someone some time.

like image 113
Johann Stolz Avatar answered Sep 22 '22 00:09

Johann Stolz