summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Andrii Kulian <akulian@google.com> 2019-03-04 22:38:03 -0800
committer Andrii Kulian <akulian@google.com> 2019-03-05 13:39:16 -0800
commit76ea768bd3efa8800400769b5e4bef45ef2561ea (patch)
tree3de2e0a17662c51b8820cf30572f0925794ad047
parent475f8da097c0589f8bcd148d04c260a5b1030819 (diff)
Allow transitioning through lifecycle when finished
When finish was requested for an activity, certain lifecycle transitions were blocked to avoid delivering invalid callbacks in the past. The checks and early returns that were left from the old way of resolving lifecycle cancelled delivering STARTED, RESUMED and PAUSED state if an activity called finish(). This is no longer required with Lifecycler infrastructure that takes care of ensuring validity of all transition sequences. Bug: 127106719 Bug: 126693030 Test: ActivityLifecycleTests#testFinishInOn* Change-Id: Ia9e76dae2f2b5cede046140ef0f196a07accb8c3
-rw-r--r--core/java/android/app/ActivityThread.java35
1 files changed, 10 insertions, 25 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index b654258e6dcb..0e2b504a15ab 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -3129,10 +3129,6 @@ public final class ActivityThread extends ClientTransactionHandler {
if (!r.stopped) {
throw new IllegalStateException("Can't start activity that is not stopped.");
}
- if (r.activity.mFinished) {
- // TODO(lifecycler): How can this happen?
- return;
- }
// Start
activity.performStart("handleStartActivity");
@@ -3255,6 +3251,8 @@ public final class ActivityThread extends ClientTransactionHandler {
if (!r.activity.mFinished && pendingActions != null) {
pendingActions.setOldState(r.state);
pendingActions.setRestoreInstanceState(true);
+ }
+ if (pendingActions != null) {
pendingActions.setCallOnPostCreate(true);
}
} else {
@@ -3958,7 +3956,7 @@ public final class ActivityThread extends ClientTransactionHandler {
if (localLOGV) {
Slog.v(TAG, "Performing resume of " + r + " finished=" + r.activity.mFinished);
}
- if (r == null || r.activity.mFinished) {
+ if (r == null) {
return null;
}
if (r.getLifecycleState() == ON_RESUME) {
@@ -4228,12 +4226,6 @@ public final class ActivityThread extends ClientTransactionHandler {
private Bundle performPauseActivity(ActivityClientRecord r, boolean finished, String reason,
PendingTransactionActions pendingActions) {
if (r.paused) {
- if (r.activity.mFinished) {
- // If we are finishing, we won't call onResume() in certain cases.
- // So here we likewise don't want to call onPause() if the activity
- // isn't resumed.
- return null;
- }
RuntimeException e = new RuntimeException(
"Performing pause of activity that is not resumed: "
+ r.intent.getComponent().toShortString());
@@ -4353,20 +4345,13 @@ public final class ActivityThread extends ClientTransactionHandler {
boolean saveState, boolean finalStateRequest, String reason) {
if (localLOGV) Slog.v(TAG, "Performing stop of " + r);
if (r != null) {
- if (!keepShown && r.stopped) {
- if (r.activity.mFinished) {
- // If we are finishing, we won't call onResume() in certain
- // cases. So here we likewise don't want to call onStop()
- // if the activity isn't resumed.
- return;
- }
- if (!finalStateRequest) {
- final RuntimeException e = new RuntimeException(
- "Performing stop of activity that is already stopped: "
- + r.intent.getComponent().toShortString());
- Slog.e(TAG, e.getMessage(), e);
- Slog.e(TAG, r.getStateString());
- }
+ if (!keepShown && r.stopped && !finalStateRequest) {
+ // Double stop request is possible if activity receives 'sleep' followed by 'stop'.
+ final RuntimeException e = new RuntimeException(
+ "Performing stop of activity that is already stopped: "
+ + r.intent.getComponent().toShortString());
+ Slog.e(TAG, e.getMessage(), e);
+ Slog.e(TAG, r.getStateString());
}
// One must first be paused before stopped...