From 6c675a3a48260077dedfd23679f55d833f3ea526 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Wed, 4 Aug 2021 10:13:13 +0800 Subject: [PATCH] Fix NPE when calling recreate in onCreate ActivityClientRecord#activity is assigned after calling Activity#onCreate. A use case is that the app uses support library to set night mode in onCreate. Bug: 195418295 Test: Invoke Activity#recreate() in Activity#onCreate. Change-Id: I6319cd6ee94fc2603979da47303963d04168db04 --- core/java/android/app/ActivityThread.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index dbaf2757a9e25..0c64c86daf3ee 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -5654,8 +5654,8 @@ public final class ActivityThread extends ClientTransactionHandler */ private void scheduleRelaunchActivityIfPossible(@NonNull ActivityClientRecord r, boolean preserveWindow) { - if (r.activity.mFinished || r.token instanceof Binder) { - // Do not schedule relaunch if the activity is finishing or not a local object (e.g. + if ((r.activity != null && r.activity.mFinished) || r.token instanceof Binder) { + // Do not schedule relaunch if the activity is finishing or is a local object (e.g. // created by ActivtiyGroup that server side doesn't recognize it). return; }