Search code examples
androidgoogle-glassgoogle-gdk

Creating Immersions, android:immersive="true" flag


Per the Creating Immersions documentation one can Specify android:immersive="true" for your <activity> element to give immersions focus after a screen sleeps and wakes up.

From my experience, this returns you to the last activity that the user was on before Glass went to sleep, for example: If the user went to ActivityA, then ActivityB, then ActivityC, and Glass goes to sleep, when the user wakes Glass up they're returned to ActivityC.

Is there a way to have the user returned to a specific activity? Say, the same scenario happens as described above, but when Glass wakes up the user is returned to ActivityA?

Thanks in advance, Cole


Solution

  • Create a member boolean variable like mInitialLaunch in Activity B and C. In onCreate of Activity B and C set mInitialLaunch to true.

    At the end of onResume in B and C, set mInitialLaunch to false.

    At the start of onResume in B and C, check mInitialLaunch and if it is false (meaning only onResume was called) launch Activity A.

    This is a way to game the Activity LifeCycle to do what you want.

    If you want more information about the Activity LifeCycle and Glass ...

    This is an open source project I created to help students learning Glass and Android basics get up to speed on the Activity LifeCycle:

    https://github.com/mscheel/glass-book-activity-lifecycle-explorer