I am using navigation graph for the first time so need help regarding the same.
In my application I have MainActivity with 5 nested graphs.
<?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/main_navigation" app:startDestination="@+id/home_navigation"> <include app:graph="@navigation/home_navigation" /> <include app:graph="@navigation/explorer_navigation" /> <include app:graph="@navigation/favourite_navigation" /> <include app:graph="@navigation/server_navigation" /> <include app:graph="@navigation/settings_navigation" /> </navigation>
Now, I need suggestion for below things
1.Need to implement a common error screen for multiple error types with an action button.
2.Need to provide call back from this error screen on pressing action button with some data on previous screen
3.I also want to send action from child navigation to parent navigation to navigate on other destination.
Thankyou in advance.
For 1st, Currently I have added error fragment for separately for each nested graph which added overhead to handle error page separately.
`
<action android:id="@+id/action_global_fragment_settings"
app:destination="@id/fragment_settings"/>
<fragment
android:id="@+id/fragment_settings"
android:name="com.xyz.android.ui.settings.SettingsBaseFragment"
android:label="@string/title_settings">
<action
android:id="@+id/action_fragment_settings_to_fragment_error"
app:destination="@id/fragment_error" />
<action
android:id="@+id/action_fragment_settings_to_settings_details_fragment"
app:destination="@id/fragment_settings_details" />
</fragment>
<fragment
android:id="@+id/fragment_error"
android:name="com.xyz.android.ui.nodata.ErrorBaseFragment">
<argument
android:name="title"
android:defaultValue="NO_DATA"
app:argType="string" />
<argument
android:name="errorType"
app:argType="com.xyz.android.ui.nodata.EnumErrorType"
android:defaultValue="NO_DATA" />
</fragment>
<fragment
android:id="@+id/fragment_settings_details"
android:name="com.xyz.android.ui.settings.SettingsBaseFragmentDetails">
<argument
android:name="settingsConfig"
app:argType="com.xyz.android.ui.settings.beans.SettingsConfigHelper$SettingsConfig" />
</fragment>
`
For 2nd, Still I have not found way to send call back to previous fragment with data.
For 3rd, I have used shared view model but need better approach.