Change theme
Help
Press space for more information.
Show links for this issue (Shortcut: i, l)
Copy issue ID
Previous Issue (Shortcut: k)
Next Issue (Shortcut: j)
Sign in to use full features.
Vote: I am impacted
Notification menu
Refresh (Shortcut: Shift+r)
Go home (Shortcut: u)
Pending code changes (auto-populated)
View issue level access limits(Press Alt + Right arrow for more information)
Attachment actions
Unintended behavior
View staffing
Description
Component used: Fragment
Version used: 1.6.0-alpha02 (starting from 1.5.0-alpha01)
Devices/Android versions reproduced on: Pixel 6 (Android 13), Pixel 5 (Android 12)
Problem description:
onConfigurationChanged()
of Fragments, within Activities which handle the orientation change themself, is called multiple times in certain cases.Project sample setup:
supportFragmentManager
childFragmentManager
When the device orientation changes
onConfigurationChanged()
is called once for the Activity and Fragment 1, but twice for Fragment 2.Technical details:https://android.googlesource.com/platform/frameworks/support/+/327c6affed80e7117144f9e0bf6cb0a9015a5d91
The behaviour change was introduced in
androidx.fragment:fragment-ktx:1.5.0-alpha01
in the following commit:An
OnConfigurationChangedProvider
was added to theComponentActivity
which is used in theFragmentManager
to notify theFragments
about configuration changes.The problem of this change is the following:
Each
Fragment
that is added gets registered on an orientation change in theActivity
. On orientation change theFragmentManager
of theActivity
notifies eachFragment
about the orientation change while eachFragment
itself also notifies its ownFragmentManager
about the notification change which again notifies each childFragment
.This ends up in the following notify calls in an example where 3 Fragments are attached in each other:
Sample project:
The sample shows the issue described above using 2 Fragments. It uses the latest
AppCompat
version1.5.1
together withFragment
1.6.0-alpha02
. Added logging toonConfigurationChanged()
of all Fragments and the Activity.The output for an orientation change is the following: