Android navigation component - unregister LiveData after navigation

Viewed 47

I am using Android Navigation Component to navigate between fragment screens.

After navigating to a new fragment screen, I want to unregister all the LiveData observations that I registered using the fragment life cycle. The problem is that the fragment is not getting detached until the navigation is complete and I am getting unintended events from LiveData.

How to handle this?

I tried using app:popUpTo but that happens too late.

Any ideas on how to solve this?

0 Answers
Related