Status Update
Comments
il...@google.com <il...@google.com>
ap...@google.com <ap...@google.com> #2
I am not sure I understand what you are asking for here.
The contract of onPrepareMenu
in MenuProvider
is:
"Called by the MenuHost right before the Menu is shown. This should be called when the menu has been dynamically updated."
If you were using Toolbar
prior to the MenuHost
integration, this should be a no-op for you. And if you are now switching to Toolbar, the onPrepareMenu()
call should be in the proper place.
But the contract is not being violated.
If you are seeing some unexpected behavior, please provide a sample app that reproduces the error that you are observing.
ap...@google.com <ap...@google.com> #3
reuploading my previous sample app.
It's fairly simple.
Call order with AppCompat 1.5.0-alpha01:
- onCreateMenu
- onPrepareMenu
- user opens menu
- menu is displayed
According to the contract:
"Called by the MenuHost right before the Menu is shown.
it should be:
- onCreateMenu
- user opens menu
- onPrepareMenu
- menu is displayed
build and run the sample. It has examples for both activity and fragment. Follow the print out's in the log.
ap...@google.com <ap...@google.com> #4
Branch: androidx-main
commit 723f2ef10ea1de61e94de16b917cc6e939bfc211
Author: Jeremy Woods <jbwoods@google.com>
Date: Tue Aug 02 17:05:42 2022
Fix Toolbar onPrepareMenu timing with MenuHost
Instead of unconditionally calling onPrepareMenu() when Toolbar executes
onCreateMenu(), it should wait until the menu is about to be shown to
make the call.
This will ensure that Toolbar properly fulfills the MenuHost contract.
RelNote: "Toolbar will now call `onPrepareMenu()` before the menu is shown
instead of unconditionally when the menu is created."
Test: modified the ToolbarMenuHostTest
Bug: 232206677
Change-Id: I2a58df0064c08b9ae87962a41d87e7bc60073df0
M appcompat/appcompat/src/main/java/androidx/appcompat/widget/Toolbar.java
M appcompat/appcompat/src/androidTest/java/androidx/appcompat/widget/ToolbarMenuHostTest.kt
ap...@google.com <ap...@google.com> #5
This has been fixed internally and will be available in the AppCompat 1.6.0-beta01
release.
ap...@google.com <ap...@google.com> #6
ap...@google.com <ap...@google.com> #7
ap...@google.com <ap...@google.com> #8
Branch: androidx-main
commit 79febb5c150c47c99d52b8708775c49220195bbd
Author: Sanura N'Jaka <sanura@google.com>
Date: Wed Jun 08 04:24:21 2022
Have saveFragmentInstanceState return full state bundle
FragmentManager's saveFragmentInstanceState should
return the entire state bundle, not just the bundle
that was constructed in
FragmentStateManager.saveBasicState().
RelNote: "`FragmentManager`'s
`saveFragmentInstanceState` now returns the entire
state of the fragment, segmented, and not just
the bundle contructed during the fragment's
`onSaveInstanceState` callback."
Test: ran all tests in
Bug: 207158202
Change-Id: I1ffaf774b7fcaf45686379e9aebeeba1416ab61f
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentStateManager.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentManager.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentState.java
M fragment/fragment/src/main/java/androidx/fragment/app/Fragment.java
jb...@google.com <jb...@google.com>
il...@google.com <il...@google.com>
ap...@google.com <ap...@google.com> #9
Branch: androidx-main
commit 08ba745b9fda03c8a6c08b3f5abd4dbcdbf60ff5
Author: Ian Lake <ilake@google.com>
Date: Thu Jun 23 22:56:52 2022
Move target fragment into FragmentState
Co-locate the target fragment's unique identifier
and request code with other library state in the
FragmentState object.
Test: existing tests pass
BUG: 207158202
Change-Id: If7ee5d7729335b1ff3c2fa5d671d698d7aebb433
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentStateManager.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentState.java
ap...@google.com <ap...@google.com> #10
Branch: androidx-main
commit 775876606f25d109a6833503514834b428f7bb1e
Author: Ian Lake <ilake@google.com>
Date: Fri Jun 24 00:05:17 2022
Move Fragment savedInstanceState out of FragmentState
Rather than FragmentState having a mix of
library state and user saved state (i.e., the state
returned by onSaveInstanceState()), these should be
stored independently from one another.
Test: existing tests pass
BUG: 207158202
Change-Id: If158c0e860aa7463252bc179673658b7696c3371
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentStateManager.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentState.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentManager.java
M fragment/fragment/src/main/java/androidx/fragment/app/Fragment.java
M fragment/fragment/src/main/java/androidx/fragment/app/BackStackState.java
ap...@google.com <ap...@google.com> #11
Branch: androidx-main
commit bf62dd252aae22511da44fc8bb4975e57abedfa3
Author: Ian Lake <ilake@google.com>
Date: Thu Jun 23 23:07:37 2022
Move user visible hint into FragmentState
Co-locate the userVisibleHint flag with the
other library state in the FragmentState object.
Test: existing tests pass
BUG: 207158202
Change-Id: I8bdd5ee138aa1d6505df9e806635eb78bca69729
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentStateManager.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentState.java
ap...@google.com <ap...@google.com> #12
Branch: androidx-main
commit 1deb87b58f32ad191ba066ab5d48740d45c95464
Author: Ian Lake <ilake@google.com>
Date: Fri Jun 24 17:53:01 2022
Move Fragment View State out of savedInstanceState Bundle
Rather than include the Fragment's SparseArray<Parcelable>
of its view's state or the Fragment View's SavedStateRegistry
bundle as part of the Bundle returned by onSaveInstanceState,
store those as separate values in the Fragment's
saved state Bundle.
Test: existing tests pass
BUG: 207158202
Change-Id: I3abfc7db186e6a921b00193fff27c62199687976
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentStateManager.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentManager.java
ap...@google.com <ap...@google.com> #13
Branch: androidx-main
commit 8a019327ad267d6251167e400ea79cb8a54243b3
Author: Ian Lake <ilake@google.com>
Date: Fri Jun 24 20:53:15 2022
Move childFragmentManager state out of savedInstanceState
Migrate the childFragmentManager state out of the same
Bundle as is passed to onSaveInstanceState(). Instead,
store that Bundle as a separate value in the Fragment's
saved state Bundle.
Test: existing tests pass
BUG: 207158202
Change-Id: I456259053dfc833d39c4f648e23735b98cb65714
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentStateManager.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentManager.java
M fragment/fragment/src/main/java/androidx/fragment/app/Fragment.java
ap...@google.com <ap...@google.com> #14
Branch: androidx-main
commit 3ccf9b6e609c6f2130689bb2f8c4bff6e2907df3
Author: Ian Lake <ilake@google.com>
Date: Fri Jun 24 21:38:19 2022
Use all initial state when saving an initializing fragment
With the state split across multiple fields, saving the
state of an Fragment still in the INITIALIZING state should
use the entire saved state Bundle set by
setInitialSavedState() rather than only extracting the
onSaveInstanceState() bundle out of it.
Test: existing tests pass
BUG: 207158202
Change-Id: I95868473b28b179d7cc0b0e606427928982dc96c
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentStateManager.java
ap...@google.com <ap...@google.com> #15
Branch: androidx-main
commit f7ec0cc1786b4a16c0569cc07ecf5093693bcab0
Author: Ian Lake <ilake@google.com>
Date: Fri Jun 24 21:30:15 2022
Skip empty/null keys when saving Fragment state
Each key in the Fragment's saved state Bundle takes up
space in the limited resource that is the total
saved instance state. By removing empty or null keys,
we can ensure that the set of saved key/values is
minimized.
Test: existing tests pass
BUG: 207158202
Change-Id: I4e0f4772982406bfe10e64d78d26e93f4e2bc387
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentStateManager.java
ap...@google.com <ap...@google.com> #16
Branch: androidx-main
commit 5cc7478b61c2f48452770285d7ba8c74be907b19
Author: Ian Lake <ilake@google.com>
Date: Fri Jun 24 21:18:57 2022
Move SavedStateRegistry state out of savedInstanceState
Migrate the SavedStateRegistry's state out of the same
Bundle as is passed to onSaveInstanceState(). Instead,
store that Bundle as a separate value in the Fragment's
saved state Bundle.
Test: existing tests pass
BUG: 207158202
Change-Id: I903d56901e6c5a5caf2890a4dbe5471c73169b56
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentStateManager.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentManager.java
M fragment/fragment/src/main/java/androidx/fragment/app/Fragment.java
ap...@google.com <ap...@google.com> #17
Branch: androidx-main
commit 28e7a78343af524c7854a3f951809448a8457dd1
Author: Ian Lake <ilake@google.com>
Date: Fri Jun 24 21:58:43 2022
Move and rename _TAG constants to _KEY
Rename all constants used as Bundle keys to use
the _KEY suffix rather than _TAG to prevent mistaking
them for debug tags.
Also moves all keys associated with the Fragment's state
into FragmentStateManager, which is responsible for
saving the Fragment's state. Keys associated with saving
the FragmentManager's state are still in FragmentManager.
Test: existing tests pass
BUG: 207158202
Change-Id: I6e47a4a0ec84c708f9a3c984e737ed7314530156
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentStateManager.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentManager.java
M fragment/fragment/src/main/java/androidx/fragment/app/BackStackState.java
M fragment/fragment/src/main/java/androidx/fragment/app/Fragment.java
M fragment/fragment/src/androidTest/java/androidx/fragment/app/BackStackStateTest.kt
il...@google.com <il...@google.com> #18
The saved state of Fragments has been split entirely between private library state (custom Parcelable
classes) and state provided by you, the developer, which is now always stored in a Bundle
that allows determining exactly which part of the fragment's state is too large.
The final structure is as follows:
In the Activity's onSaveInstanceState
, the "android:support:fragments"
key now contains a Bundle that contains the following information:
"state"
- the privateParcelable
storing theFragmentManager
's saved state (e.g., the fragment back stack info)- For each
that has been set viaFragment Result setFragmentResult
but has not yet been delivered:"result_$name"
-> (user defined Bundle) - For each Fragment (where the
fragment_id
matches the UUIDs found in the ):debug logging "fragment_$fragment_id"
-> Bundle"state"
-> the privateParcelable
storing theFragment
's saved state (e.g., the class name, max lifecycle, etc.)"arguments"
-> (Bundle of arguments)"savedInstanceState"
-> (onSaveInstanceState
filled Bundle)"registryState"
-> (SavedStateRegistry
filled Bundle)"childFragmentManager"
-> The “android:support:fragments” equivalent Bundle of the childFragmentManager
, which would lead us recursively down the tree"viewState"
-> theSparseArray<Parcelable>
returned byView.saveHierarchyState
representing theFragment View state "viewRegistryState"
-> (ViewSavedStateRegistry
filled Bundle)
This will be fully available in Fragment 1.6.0-alpha01.
Description
Component used: Fragment
Version used: 1.4.0
There are tools like toolargetool that let you explore what is taking up space in your saved instance state. However, it has no visibility into custom Parcelables like the
FragmentManagerState
used to store the entire FragmentManager's hierarchy of saved state.This makes it hard to differentiate between the state of the FragmentManager itself and the state of each individual fragment, and, within a particular fragment, differentiating the view state, arguments, state provided by
onSaveInstanceState()
, and the fragment'sSavedStateRegistry
.Therefore the focus should be on exposing the hierarchy of fragments - the bookkeeping associated with an individual Fragment and the FragmentManager specific state can and should remain as separate Parcelable instances that don't expose their internal fields.