Add error handling for onConfigurationChanged

The new config may comes before mApplication is assigned. Add the error
handling to prevent the crash.

Bug: 211031909
Test: Launch app without crash
Change-Id: Iba5d1be0e6cb182b5f503f5aa827eb2967834d52
This commit is contained in:
Chilun
2022-01-20 23:39:13 +08:00
parent fd16e8c352
commit cca803cba8

View File

@@ -1537,7 +1537,10 @@ public class Activity extends ContextThemeWrapper
}
private void dispatchActivityConfigurationChanged() {
getApplication().dispatchActivityConfigurationChanged(this);
// In case the new config comes before mApplication is assigned.
if (getApplication() != null) {
getApplication().dispatchActivityConfigurationChanged(this);
}
Object[] callbacks = collectActivityLifecycleCallbacks();
if (callbacks != null) {
for (int i = 0; i < callbacks.length; i++) {