Newbie on Navigation Component. I'm trying to achieve this but I don't know how:
I have 3 fragments:
FragmentMain
→ FragmentList
→ FragmentAdd
If I try to go from FragmentMain
to FragmentList
but list is empty it should go directly to FragmentAdd
(its not really directly since I'm checking the list on FragmentList but for the user it should look like it). If I'm on FragmentAdd
and I go back (by either pressing back button or back on the toolbar) it should go back to FragmentMain
(since FragmentList
is still empty) but if I add something it should go back to FragmentList
.
I've tried with
<fragment
android:id="@+id/fragmentMain" >
<action android:id="@+id/action_fragmentMain_to_fragmentList
app:destination="@id/fragmentList"
app:popUpTo="@id/fragmentMain"
app:popUpToInclusive="true"/>
</fragment>
The thing is that if I press back on FragmentAdd
it will go to FragmentList
, check that the list is still empty and go back to FragmentAdd
. And if I pop FragmentList
and then add something It will go to FragmentMain
and not the list.
The difference with Conditional back navigation with Android Navigation Component is that I can add stuff to FragmentList
from FragmentAdd
Any suggestion please?