Status Update
Comments
ma...@caringvillage.com <ma...@caringvillage.com> #2
So there does seem to be a bug in Navigation that causes this to fail.
When it navigates with popUpTo
and removes SecondFragment
, that removal in fragment is set for a frame later and before it is actually removed the navigate call in the onViewCreated
of SecondFragment
enqueues another call to add it back. But we still need to destroy SecondDetailFragment
which ends up marking the NavBackStackEntry
associated with SecondFragment
as complete before navigation has received the call from the fragment that it has been added back. So by the time it hits this check, the SecondFragment
is in the correct state, but Navigation has no way of referencing it so it assumes that it is not associated with an entry.
But this is not the way this type of situation should be implemented. Instead of having the destinations as part of the NavGraph, they should:
- be managed by the childFragmentManager of
SecondFragment
. So instead of going back toSecondFragment
just to go somewhere else, each of the fragments take the entire content ofSecondFragment
and are swapped out. - for some sort of a/b testing, set different graphs in the Activity. The graphs would keep the same
SecondFragment
id, but swap out the names and then you choose the correct graph based on the condition.
da...@google.com <da...@google.com> #3
da...@google.com <da...@google.com>
ap...@google.com <ap...@google.com> #4
- Have
SecondFragment
as part of your graph and then inside ofSecondFragment
call thechildFragmentManager
andreplace
with the fragment you actually want to show, whether that isSecondTypeOne
orSecondTypeTwo
. - Create different graphs and follow along with the
on using different graphs dynamically and inflate and set the one needed based on logic in your Activity.docs
da...@google.com <da...@google.com>
pr...@google.com <pr...@google.com> #5
shardViewModel.onGetTypeSecond.observe(viewLifecycleOwner) { isType1 ->
if (isType1) {
val graph = findNavController().graph
val carInstallmentNavGraph =
graph.findNode(R.id.nav_second) as NavGraph
carInstallmentNavGraph.setStartDestination(R.id.secondTypeOneFragment)
findNavController().navigate(SecondFragmentDirections.actionSecondFragmentToSecondTypeOneFragment())
} else {
val graph = findNavController().graph
val carInstallmentNavGraph =
graph.findNode(R.id.nav_second) as NavGraph
carInstallmentNavGraph.setStartDestination(R.id.secondTypeTwoFragment)
findNavController().navigate(SecondFragmentDirections.actionSecondFragmentToSecondTypeTwoFragment())
}
}
and removed app:popUpTo="@id/secondFragment" and app:popUpToInclusive="true"
<fragment
android:id="@+id/secondFragment"
android:name="com.example.navigationdeeplink.SecondFragment"
android:label="fragment_second"
tools:layout="@layout/fragment_second" >
<action
android:id="@+id/action_secondFragment_to_secondTypeOneFragment"
app:destination="@id/secondTypeOneFragment" />
<action
android:id="@+id/action_secondFragment_to_secondTypeTwoFragment"
app:destination="@id/secondTypeTwoFragment"
app:popUpTo="@id/secondFragment" />
</fragment>
Description
I'm using:
My databases are configured with:
When a destructive migration occurs we're getting an error on Android (and I believe we're getting a similar error on iOS, but am awaiting confirmation on that).
I pulled the db from device explorer, and it looks like the "destructive" part of the migration never completed? All the tables and views are is still present - but it's all in the .wal file (first time I just pulled the .db file, and it was empty).
Clearing storage, or uninstall+reinstall resolves the issue, but that's less than ideal, and as soon as the db version is bumped again, even if no other changes are made to the code, it happens again.
It's odd that this appears to have just popped up recently, after a couple of minor changes, after appearing to have been working fine for the last ~15 or so destructive migrations.