diff options
| author | 2018-05-04 11:41:59 -0700 | |
|---|---|---|
| committer | 2018-05-04 11:41:59 -0700 | |
| commit | aad8cbf14e0ef304f47024cab04a51155b29c24e (patch) | |
| tree | a186f70562223d27dfb5bda225fa6a710e2fbd2b | |
| parent | a6c4a09f3c3dab53ea2ab8d7c8d65314b42ba362 (diff) | |
| parent | 1ed9f4294c408dade7575cae9a7814f79b965be6 (diff) | |
Merge "Schedule local activity relaunch" into pi-dev
am: 1ed9f4294c
Change-Id: I7ff272e057bed855ce187aa759f197807a50d683
| -rw-r--r-- | core/java/android/app/Activity.java | 2 | ||||
| -rw-r--r-- | core/java/android/app/ActivityThread.java | 29 |
2 files changed, 22 insertions, 9 deletions
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java index b456b72d8bf7..3b62bd7cb057 100644 --- a/core/java/android/app/Activity.java +++ b/core/java/android/app/Activity.java @@ -5578,7 +5578,7 @@ public class Activity extends ContextThemeWrapper if (mParent != null) { throw new IllegalStateException("Can only be called on top-level activity"); } - mMainThread.handleRelaunchActivityLocally(mToken); + mMainThread.scheduleRelaunchActivity(mToken); } /** diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 3f667472f136..a183f735d74a 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -1555,6 +1555,7 @@ public final class ActivityThread extends ClientTransactionHandler { public static final int APPLICATION_INFO_CHANGED = 156; public static final int RUN_ISOLATED_ENTRY_POINT = 158; public static final int EXECUTE_TRANSACTION = 159; + public static final int RELAUNCH_ACTIVITY = 160; String codeToString(int code) { if (DEBUG_MESSAGES) { @@ -1598,6 +1599,7 @@ public final class ActivityThread extends ClientTransactionHandler { case APPLICATION_INFO_CHANGED: return "APPLICATION_INFO_CHANGED"; case RUN_ISOLATED_ENTRY_POINT: return "RUN_ISOLATED_ENTRY_POINT"; case EXECUTE_TRANSACTION: return "EXECUTE_TRANSACTION"; + case RELAUNCH_ACTIVITY: return "RELAUNCH_ACTIVITY"; } } return Integer.toString(code); @@ -1780,6 +1782,9 @@ public final class ActivityThread extends ClientTransactionHandler { } // TODO(lifecycler): Recycle locally scheduled transactions. break; + case RELAUNCH_ACTIVITY: + handleRelaunchActivityLocally((IBinder) msg.obj); + break; } Object obj = msg.obj; if (obj instanceof SomeArgs) { @@ -4284,7 +4289,7 @@ public final class ActivityThread extends ClientTransactionHandler { for (Map.Entry<IBinder, ActivityClientRecord> entry : mActivities.entrySet()) { final Activity activity = entry.getValue().activity; if (!activity.mFinished) { - handleRelaunchActivityLocally(entry.getKey()); + scheduleRelaunchActivity(entry.getKey()); } } } @@ -4662,21 +4667,29 @@ public final class ActivityThread extends ClientTransactionHandler { } } - /** Performs the activity relaunch locally vs. requesting from system-server. */ - void handleRelaunchActivityLocally(IBinder token) { - if (Looper.myLooper() != getLooper()) { - throw new IllegalStateException("Must be called from main thread"); - } + /** + * Post a message to relaunch the activity. We do this instead of launching it immediately, + * because this will destroy the activity from which it was called and interfere with the + * lifecycle changes it was going through before. We need to make sure that we have finished + * handling current transaction item before relaunching the activity. + */ + void scheduleRelaunchActivity(IBinder token) { + sendMessage(H.RELAUNCH_ACTIVITY, token); + } + /** Performs the activity relaunch locally vs. requesting from system-server. */ + private void handleRelaunchActivityLocally(IBinder token) { final ActivityClientRecord r = mActivities.get(token); if (r == null) { + Log.w(TAG, "Activity to relaunch no longer exists"); return; } final int prevState = r.getLifecycleState(); - if (prevState < ON_RESUME) { - Log.w(TAG, "Activity needs to be already resumed in other to be relaunched."); + if (prevState < ON_RESUME || prevState > ON_STOP) { + Log.w(TAG, "Activity state must be in [ON_RESUME..ON_STOP] in order to be relaunched," + + "current state is " + prevState); return; } |