Using Navigation component graph in Wear OS

Navigation component is very useful for Android applications. It provides fragment lifecycle management, high level navigation abstraction, integration with drawer, etc. Wear OS applications have their own navigation drawer, which is not integrated with components, but still, navigation components is useful for lifecycle and abstraction in Wear OS apps too.

Setup for Wear OS is similar to Android applications: libs, xml, direction classes, etc. Only missing feature is drawer integration, so when you navigate fragments outside of drawer, it should correctly update current location. Easiest way to do it, just add drawer update in onResume method like:

    @Override
    public void onResume() {
        super.onResume();
        activity.mWearableNavigationDrawer.setCurrentItem(navigationAdapter.getIndex(NavigationItems.PREFERENCES), false);
        ...
    }

Comments