Issue
I have this Activity (subclass of AppCompatActivity):
<activity
android:name=".ui.settings.SettingsActivity"
android:configChanges="keyboardHidden|smallestScreenSize|orientation|screenSize|screenLayout"
android:launchMode="singleTask"
android:parentActivityName=".ui.main.MainActivity" />
Now, when I rotate the phone while in normal (i. e. "Day") mode I get a call to onConfigurationChanged but the Activity is not re-created.
However, when the app is set to Night Mode (by calling AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) in my Application before the Activity is created) and I then rotate the phone, I first get a call to onConfigurationChanged but then the Activity is also re-created, even though the uiMode has not changed at all! This goes away when I add uiMode to the configChanges that should be ignored in my AndroidManifest.xml, but it seems weird that I need to do this.
From looking through the source it seems that:
onConfigurationChangedcallsgetDelegate().onConfigurationChanged(newConfig);which goes toAppCompatDelegateImpl.onConfigurationChanged(newConfig)- there,
applyDayNight()gets called - there,
getNightModereturnsAppCompatDelegateImpl.MODE_NIGHT_YES, which makes sense since this is what I set it to.mapNightModejust returns that value unchanged. ThenupdateForNightMode(AppCompatDelegateImpl.MODE_NIGHT_YES)gets called - there,
newNightModeis calculated correctly to beConfiguration.UI_MODE_NIGHT_YESbutcurrentNightMode(which is read in frommContext.getResources().getConfiguration().uiMode) always appears to beConfiguration.UI_MODE_NIGHT_NOafter each rotation, even if theActivitywas rendered in Night Mode before the rotation.
So, what's going on here and what could I do to get more consistent behavior? (Re-create (or not) the Activity after a screen rotation, regardless of whether the app is in Night Mode or not.)
Solution
Seems to be a bug and will be fixed in AppCompat v1.1.0 according to this issue.
Starting with AppCompat v1.1.0-alpha03 you no longer need the uiMode-flag in the configChanges as a workaround
Answered By - matt.mic
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.