Fixed
Status Update
Comments
il...@google.com <il...@google.com>
ap...@google.com <ap...@google.com> #2
This actually has nothing to do with NavHostFragment, but is the behavior of NavController's setGraph().
When you call navController.setGraph(R.navigation.navigation_graph), it stores that ID and will restore that ID automatically.
If you were to instead use:
NavInflater navInflater = new NavInflater(this, navController.getNavigatorProvider());
navController.setGraph(navInflater.inflate(R.navigation.navigation_graph));
Then NavController would not restore the graph itself and the call to restoreState() you point out would only restore the back stack state, etc. but would wait for you to call setGraph again.
You're right that the inconsistency between the two setGraph methods is concerning. We'll take a look.
When you call navController.setGraph(R.navigation.navigation_graph), it stores that ID and will restore that ID automatically.
If you were to instead use:
NavInflater navInflater = new NavInflater(this, navController.getNavigatorProvider());
navController.setGraph(navInflater.inflate(R.navigation.navigation_graph));
Then NavController would not restore the graph itself and the call to restoreState() you point out would only restore the back stack state, etc. but would wait for you to call setGraph again.
You're right that the inconsistency between the two setGraph methods is concerning. We'll take a look.
na...@google.com <na...@google.com> #3
Turns out, we already had a tracking bug for this issue, will follow up on that other one.
Description
Build: AI-212.5712.43.2112.8815526, 202207101541,
AI-212.5712.43.2112.8815526, JRE 11.0.12+0-b1504.28-7817840x64 JetBrains s.r.o., OS Mac OS X(x86_64) v11.6.8, screens 2560.0x1440.0
AS: Chipmunk | 2021.2.1 Patch 2; Kotlin plugin: 212-1.7.10-release-333-AS5457.46; Android Gradle Plugin: 7.2.2; Gradle: 7.3.3; Gradle JDK: version 11.0.12; NDK: from local.properties: (not specified), latest from SDK: (not found); LLDB: pinned revision 3.1 not found, latest from SDK: (package not found); CMake: from local.properties: (not specified), latest from SDK: (not found), from PATH: (not found)
========
Description:
Function
addSource(LiveData<S> source, Observer<? super S> onChanged)
inandroidx.lifecycle.MediatorLiveData<T>
has a typo in its comments.Currently says:
"Starts to listen the given source LiveData,"
Expected:
"Starts to listen to the given source LiveData,"
============ Copy/paste from IDE:
androidx.lifecycle.MediatorLiveData<T> @MainThread public <S> void addSource( @NonNull androidx.lifecycle.LiveData<S> source, @NonNull androidx.lifecycle.Observer<? super S> onChanged)
Starts to listen the given source LiveData, onChanged observer will be called when source value was changed. onChanged callback will be called only when this MediatorLiveData is active. If the given LiveData is already added as a source but with a different Observer, IllegalArgumentException will be thrown.
Params: source – the LiveData to listen to onChanged – The observer that will receive the events Type parameters: <S> – The type of data hold by source LiveData Gradle: androidx.lifecycle:lifecycle-livedata:2.5.1@aar