Reputation: 1630
I'm thinking about a new architecture for my application and I'm implementing something new to an app that already exists.
So, basically my new module has a flow, using navigation component, and when this comes to end my app need to know to call the old flow.
How do I know that? Can host activity knows when navigation end?
Upvotes: 1
Views: 3285
Reputation: 2019
Your host activity can call addOnDestinationChangedListener
so that it is aware of the current fragment in the navigation flow. If my understanding is correct, you could do something like this in your host activity's onCreate:
navController.addOnDestinationChangedListener(new NavController.OnDestinationChangedListener() {
@Override
public void onDestinationChanged(@NonNull NavController controller,
@NonNull NavDestination destination, @Nullable Bundle arguments) {
// if you have reached the end of your navigation flow, do something
if(destination.getId() == R.id.end_dest) {
// add code calling your old flow here
}
}
});
Upvotes: 4