'AppCompatActivity.onCreate still called with @NonNull Bundle
I have used this below configuration for <activty> at AndroidManifest.xml
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|screenLayout|fontScale|uiMode|orientation|density|screenSize|smallestScreenSize"
Still activity's onCreate method called with NonNull Bundle on some devices at user end. I'm not understanding how it's happing.
How can I completely disable calling activity's onCreate method with NonNull Bundle?
Solution 1:[1]
That is not possible, sorry.
Device manufacturers can change whatever they want. If they wish to introduce some new undocumented configuration change, they can do so. Even Google has some undocumented configuration changes, such as fontWeightAdjustment and colorMode.
There are also certain events that trigger things that look like configuration changes but cannot be blocked by android:configChanges.
Using android:configChanges as a way to optimize certain scenarios is fine. However, you cannot guarantee that your activity will never be recreated.
Solution 2:[2]
This would be the list of all documented Google Android R.attr.configChanges; fontWeightAdjustment is on the list. What ultimately counts is this one enum in include/androidfw/ResourceTypes.h, which indeed may vary from device to device, assuming special hardware which may cause config changes. If you want to know any possible config change, BroadcastReceiver & IntentFilter for Intent.ACTION_CONFIGURATION_CHANGED and log to Crashlytics.
But as stated, the Bundle savedinstanceState will never be null when returning ...
better wrap the code insde if (savedInstanceSate == null) {} and call it a day.
One just has to determine which code is fine to run once and which has to run every time
Trying to prevent the Activity life-cycle doesn't help, but one may have to deal with it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | CommonsWare |
| Solution 2 |
