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

Commit c8e20e0b authored by Jeff Chang's avatar Jeff Chang
Browse files

Simplify the activity lifecycle from START to STOP

When the life cycle of activity stay in START state and plan to STOP
state soon. We can jump to the STOP state directly instead of going through
the RESUME and PAUSE state. Basically, applications like to do things on
RESUME state, we don't need to let application to handle the case because
it already plan to STOP.

This CL simplify the lifecycle path for the condition and update the related
test case.

Bug: 143125452
Test: atest TransactionExecutorTests
      atest ActivityLifecycleTests

Change-Id: Id4164eae211587a2dd4e845970ef41cc38ce430d
parent baa2cea8
Loading
Loading
Loading
Loading
+9 −3
Original line number Original line Diff line number Diff line
@@ -75,10 +75,16 @@ public class TransactionExecutorHelper {


        mLifecycleSequence.clear();
        mLifecycleSequence.clear();
        if (finish >= start) {
        if (finish >= start) {
            if (start == ON_START && finish == ON_STOP) {
                // A case when we from start to stop state soon, we don't need to go
                // through the resumed, paused state.
                mLifecycleSequence.add(ON_STOP);
            } else {
                // just go there
                // just go there
                for (int i = start + 1; i <= finish; i++) {
                for (int i = start + 1; i <= finish; i++) {
                    mLifecycleSequence.add(i);
                    mLifecycleSequence.add(i);
                }
                }
            }
        } else { // finish < start, can't just cycle down
        } else { // finish < start, can't just cycle down
            if (start == ON_PAUSE && finish == ON_RESUME) {
            if (start == ON_PAUSE && finish == ON_RESUME) {
                // Special case when we can just directly go to resumed state.
                // Special case when we can just directly go to resumed state.
+4 −2
Original line number Original line Diff line number Diff line
@@ -124,7 +124,7 @@ public class TransactionExecutorTests {
        assertArrayEquals(new int[] {}, path(ON_START));
        assertArrayEquals(new int[] {}, path(ON_START));
        assertArrayEquals(new int[] {ON_RESUME}, path(ON_RESUME));
        assertArrayEquals(new int[] {ON_RESUME}, path(ON_RESUME));
        assertArrayEquals(new int[] {ON_RESUME, ON_PAUSE}, path(ON_PAUSE));
        assertArrayEquals(new int[] {ON_RESUME, ON_PAUSE}, path(ON_PAUSE));
        assertArrayEquals(new int[] {ON_RESUME, ON_PAUSE, ON_STOP}, path(ON_STOP));
        assertArrayEquals(new int[] {ON_STOP}, path(ON_STOP));
        assertArrayEquals(new int[] {ON_RESUME, ON_PAUSE, ON_STOP, ON_DESTROY}, path(ON_DESTROY));
        assertArrayEquals(new int[] {ON_RESUME, ON_PAUSE, ON_STOP, ON_DESTROY}, path(ON_DESTROY));
    }
    }


@@ -362,7 +362,9 @@ public class TransactionExecutorTests {
    public void testClosestStateResolutionFromOnStart() {
    public void testClosestStateResolutionFromOnStart() {
        mClientRecord.setState(ON_START);
        mClientRecord.setState(ON_START);
        assertEquals(ON_RESUME, mExecutorHelper.getClosestOfStates(mClientRecord, shuffledArray(
        assertEquals(ON_RESUME, mExecutorHelper.getClosestOfStates(mClientRecord, shuffledArray(
                new int[] {ON_CREATE, ON_RESUME, ON_PAUSE, ON_STOP, ON_DESTROY})));
                new int[] {ON_CREATE, ON_RESUME, ON_PAUSE, ON_DESTROY})));
        assertEquals(ON_STOP, mExecutorHelper.getClosestOfStates(mClientRecord, shuffledArray(
                new int[] {ON_STOP})));
        assertEquals(ON_CREATE, mExecutorHelper.getClosestOfStates(mClientRecord, shuffledArray(
        assertEquals(ON_CREATE, mExecutorHelper.getClosestOfStates(mClientRecord, shuffledArray(
                new int[] {ON_CREATE})));
                new int[] {ON_CREATE})));
    }
    }