Question: [I found the question but does not have solution in code](https://stackoverflow.com/q/53298615/1136023)

I want to have data when backpress/manual back happens. I am using `navigateUp()` to go back. How can I pass data to previous fragment? `navigateUp()` does not have any facility to pass data to previous fragment. Even I did not find solution using [Safe Args](https://developer.android.com/topic/libraries/architecture/navigation/navigation-pass-data#Safe-args). It's passing data forward. I want to have in backward Frad B -> Frag A.

My code to go back to previous fragment

```
Navigation.findNavController(view).navigateUp()

```

[![enter image description here](https://i.stack.imgur.com/b27YH.png)](https://i.stack.imgur.com/b27YH.png)

My question is, How can i get data in previous fragment. I can navigate to Frag A from Frag B using

Answer: 
You can use [NavigationResult](https://github.com/PHELAT/NavigationResult) library. Basically it's `startActivityForResult` but for Fragments in Navigation component.
You should use static variables/companion objects, because it is better than shared viewmodel as it is not simple/nice architecture. As it it not straightforward, I think it is the best way.

To navigateUp From FragmentB to FragmentA

FragmentB:

```
isBackpressed = true
findNavController().navigateUp() 

```

FragmentA:

```
onViewCreated() {
    // todo
    if(isBackpressed) {
         isBackpressed = false
         // do whatever you want
    }
}

```