Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ba7881c8 authored by Wale Ogunwale's avatar Wale Ogunwale
Browse files

Support finishing a task with any finishing activity in the task.

Change-Id: I8c6bb864de6dc135e0fedb16ee424d7816ee3cfa
parent 950af418
Loading
Loading
Loading
Loading
+13 −6
Original line number Diff line number Diff line
@@ -683,6 +683,13 @@ public class Activity extends ContextThemeWrapper
    /** Start of user-defined activity results. */
    public static final int RESULT_FIRST_USER   = 1;

    /** @hide Task isn't finished when activity is finished */
    public static final int DONT_FINISH_TASK_WITH_ACTIVITY = 0;
    /** @hide Task is finished if the finishing activity is the root of the task */
    public static final int FINISH_TASK_WITH_ROOT_ACTIVITY = 1;
    /** @hide Task is finished along with the finishing activity*/
    public static final int FINISH_TASK_WITH_ACTIVITY = 2;

    static final String FRAGMENTS_TAG = "android:fragments";

    private static final String WINDOW_HIERARCHY_TAG = "android:viewHierarchyState";
@@ -2689,8 +2696,8 @@ public class Activity extends ContextThemeWrapper
     * @hide
     */
    @Override
    public void onWindowDismissed() {
        finish();
    public void onWindowDismissed(boolean finishTask) {
        finish(finishTask ? FINISH_TASK_WITH_ACTIVITY : DONT_FINISH_TASK_WITH_ACTIVITY);
    }

    /**
@@ -4838,7 +4845,7 @@ public class Activity extends ContextThemeWrapper
     * Finishes the current activity and specifies whether to remove the task associated with this
     * activity.
     */
    private void finish(boolean finishTask) {
    private void finish(int finishTask) {
        if (mParent == null) {
            int resultCode;
            Intent resultData;
@@ -4869,7 +4876,7 @@ public class Activity extends ContextThemeWrapper
     * onActivityResult().
     */
    public void finish() {
        finish(false);
        finish(DONT_FINISH_TASK_WITH_ACTIVITY);
    }

    /**
@@ -4969,10 +4976,10 @@ public class Activity extends ContextThemeWrapper

    /**
     * Call this when your activity is done and should be closed and the task should be completely
     * removed as a part of finishing the Activity.
     * removed as a part of finishing the root activity of the task.
     */
    public void finishAndRemoveTask() {
        finish(true);
        finish(FINISH_TASK_WITH_ROOT_ACTIVITY);
    }

    /**
+3 −3
Original line number Diff line number Diff line
@@ -346,7 +346,7 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
            if (data.readInt() != 0) {
                resultData = Intent.CREATOR.createFromParcel(data);
            }
            boolean finishTask = (data.readInt() != 0);
            int finishTask = data.readInt();
            boolean res = finishActivity(token, resultCode, resultData, finishTask);
            reply.writeNoException();
            reply.writeInt(res ? 1 : 0);
@@ -2949,7 +2949,7 @@ class ActivityManagerProxy implements IActivityManager
        data.recycle();
        return result;
    }
    public boolean finishActivity(IBinder token, int resultCode, Intent resultData, boolean finishTask)
    public boolean finishActivity(IBinder token, int resultCode, Intent resultData, int finishTask)
            throws RemoteException {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
@@ -2962,7 +2962,7 @@ class ActivityManagerProxy implements IActivityManager
        } else {
            data.writeInt(0);
        }
        data.writeInt(finishTask ? 1 : 0);
        data.writeInt(finishTask);
        mRemote.transact(FINISH_ACTIVITY_TRANSACTION, data, reply, 0);
        reply.readException();
        boolean res = reply.readInt() != 0;
+4 −2
Original line number Diff line number Diff line
@@ -2555,7 +2555,8 @@ public final class ActivityThread {
            // manager to stop us.
            try {
                ActivityManagerNative.getDefault()
                    .finishActivity(r.token, Activity.RESULT_CANCELED, null, false);
                    .finishActivity(r.token, Activity.RESULT_CANCELED, null,
                            Activity.DONT_FINISH_TASK_WITH_ACTIVITY);
            } catch (RemoteException ex) {
                // Ignore
            }
@@ -3280,7 +3281,8 @@ public final class ActivityThread {
            // just end this activity.
            try {
                ActivityManagerNative.getDefault()
                    .finishActivity(token, Activity.RESULT_CANCELED, null, false);
                    .finishActivity(token, Activity.RESULT_CANCELED, null,
                            Activity.DONT_FINISH_TASK_WITH_ACTIVITY);
            } catch (RemoteException ex) {
            }
        }
+8 −8
Original line number Diff line number Diff line
@@ -733,7 +733,7 @@ public class Dialog implements DialogInterface, Window.Callback,

    /** @hide */
    @Override
    public void onWindowDismissed() {
    public void onWindowDismissed(boolean finishTask) {
        dismiss();
    }

+1 −1
Original line number Diff line number Diff line
@@ -93,7 +93,7 @@ public interface IActivityManager extends IInterface {
    public boolean startNextMatchingActivity(IBinder callingActivity,
            Intent intent, Bundle options) throws RemoteException;
    public int startActivityFromRecents(int taskId, Bundle options) throws RemoteException;
    public boolean finishActivity(IBinder token, int code, Intent data, boolean finishTask)
    public boolean finishActivity(IBinder token, int code, Intent data, int finishTask)
            throws RemoteException;
    public void finishSubActivity(IBinder token, String resultWho, int requestCode) throws RemoteException;
    public boolean finishActivityAffinity(IBinder token) throws RemoteException;
Loading