Snapshot:
I've got a project that is split up into multiple modules.
I have a single Application app where fragments and functionality are split into different modules.
Additionally to MainActivity I now have the AppIntro Activity. The module containing the MainActivity has a Gradle reference to the AppIntroActivity module.
Task:
From one of my slide, I need to navigate to a specific fragment (within the MainActivity).
Problem:
I can't send an Intent to the MainActivity (because the reference already goes the other way).
My Idea is therefore to reference a module that contains a navgraph that knows the way to the desired fragment.
Implementation:
Setup Gradle file with reference to "androidx.navigation:navigation-fragment-ktx" as well as the module containing the navigation graph. -> Check
Add the FragmentContainerView into the activity_onboarding.xml -> Check:
<androidx.fragment.app.FragmentContainerView android:id="@+id/nav_host_fragment" android:name="androidx.navigation.fragment.NavHostFragment" android:layout_width="0dp" android:layout_height="0dp" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toBottomOf="parent" app:defaultNavHost="true" app:navGraph="@navigation/nav_graph_onboarding" />Setup the navgraph ("nav_graph_onboarding.xml"):
<?xml version="1.0" encoding="utf-8"?> <navigation xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/nav_graph.xml" app:startDestination="@id/appIntroFragment"> <fragment android:id="@+id/appIntroFragment" android:name="com.github.appintro.AppIntroFragment" android:label="AppIntroFragment" /> <include app:graph="@navigation/nav_graph_login" /> </navigation>
First, everything looks good. The onboarding layout opens and I can navigate through it.
The Problem if this implementation is that the onClickListener (on buttons) within the slides don't react anymore. If I remove the "androidx.fragment.app.FragmentContainerView" everything works fine.
Question: How can I use the AppIntro and the navigation graph together?
Is it possible at all, or do I need a completely different approach?