0

I have the following architecture: Fragment A shows a value from an API Call, Fragment B lets the user change the value using an API Call and user can tap a button to travel from A -> B. However when the user changes the value in B and presses back, the call in A's onViewCreated() doesn't trigger so the value shown isn't updated. Looks like onResume() and onStart() also doesn't trigger when a user returns to the fragment in the Backstack.

My question is how can I handle this scenario to trigger an API call in fragment A when returning from fragment B via onBackPressed()

The code to transition from Fragment A -> B(I'm using the navigation component of Jetpack) :

findNavController().navigate(AFragmentDirections.actionAFragmentToBFragment())
    
Alex Petev
  • 501
  • 5
  • 19
  • What gets called on the previous fragment is entirely based on what kind of `FragmentTransaction` you are doing to 'travel from A -> B'. Please include your code. – ianhanniballake Aug 22 '22 at 17:50
  • Included the code as an edit. Thanks – Alex Petev Aug 22 '22 at 18:31
  • If you are using the NavController, then your fragment on the back stack is absolutely going to be getting its view recreated when you go back to it. – ianhanniballake Aug 22 '22 at 20:32
  • @ianhanniballake so you're saying when I go back to the view on the backstack I should have the view go through it's onViewCreated()? Because it seems like none of my breakpoints are being hit in Fragment A – Alex Petev Aug 22 '22 at 22:27

0 Answers0