diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 5bedc9d952379..7b4aeeca2855f 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -360,9 +360,8 @@ public final class ActivityThread extends ClientTransactionHandler /** The activities to be truly destroyed (not include relaunch). */ final Map mActivitiesToBeDestroyed = Collections.synchronizedMap(new ArrayMap()); - // List of new activities (via ActivityRecord.nextIdle) that should - // be reported when next we idle. - ActivityClientRecord mNewActivities = null; + // List of new activities that should be reported when next we idle. + final ArrayList mNewActivities = new ArrayList<>(); // Number of activities that are currently visible on-screen. @UnsupportedAppUsage int mNumVisibleActivities = 0; @@ -563,7 +562,6 @@ public final class ActivityThread extends ClientTransactionHandler private Configuration tmpConfig = new Configuration(); // Callback used for updating activity override config and camera compat control state. ViewRootImpl.ActivityConfigCallback activityConfigCallback; - ActivityClientRecord nextIdle; // Indicates whether this activity is currently the topmost resumed one in the system. // This holds the last reported value from server. @@ -657,7 +655,6 @@ public final class ActivityThread extends ClientTransactionHandler paused = false; stopped = false; hideForNow = false; - nextIdle = null; activityConfigCallback = new ViewRootImpl.ActivityConfigCallback() { @Override public void onConfigurationChanged(Configuration overrideConfig, @@ -2483,29 +2480,22 @@ public final class ActivityThread extends ClientTransactionHandler private class Idler implements MessageQueue.IdleHandler { @Override public final boolean queueIdle() { - ActivityClientRecord a = mNewActivities; boolean stopProfiling = false; if (mBoundApplication != null && mProfiler.profileFd != null && mProfiler.autoStopProfiler) { stopProfiling = true; } - if (a != null) { - mNewActivities = null; - final ActivityClient ac = ActivityClient.getInstance(); - ActivityClientRecord prev; - do { - if (localLOGV) Slog.v( - TAG, "Reporting idle of " + a + - " finished=" + - (a.activity != null && a.activity.mFinished)); - if (a.activity != null && !a.activity.mFinished) { - ac.activityIdle(a.token, a.createdConfig, stopProfiling); - a.createdConfig = null; - } - prev = a; - a = a.nextIdle; - prev.nextIdle = null; - } while (a != null); + final ActivityClient ac = ActivityClient.getInstance(); + while (mNewActivities.size() > 0) { + final ActivityClientRecord a = mNewActivities.remove(0); + if (localLOGV) { + Slog.v(TAG, "Reporting idle of " + a + " finished=" + + (a.activity != null && a.activity.mFinished)); + } + if (a.activity != null && !a.activity.mFinished) { + ac.activityIdle(a.token, a.createdConfig, stopProfiling); + a.createdConfig = null; + } } if (stopProfiling) { mProfiler.stopProfiling(); @@ -5107,8 +5097,7 @@ public final class ActivityThread extends ClientTransactionHandler } } - r.nextIdle = mNewActivities; - mNewActivities = r; + mNewActivities.add(r); if (localLOGV) Slog.v(TAG, "Scheduling idle handler for " + r); Looper.myQueue().addIdleHandler(new Idler()); } @@ -5709,6 +5698,7 @@ public final class ActivityThread extends ClientTransactionHandler } if (finishing) { ActivityClient.getInstance().activityDestroyed(r.token); + mNewActivities.remove(r); } mSomeActivitiesChanged = true; } @@ -5929,7 +5919,6 @@ public final class ActivityThread extends ClientTransactionHandler r.activity = null; r.window = null; r.hideForNow = false; - r.nextIdle = null; // Merge any pending results and pending intents; don't just replace them if (pendingResults != null) { if (r.pendingResults == null) {