Search code examples
google-glassgoogle-gdk

How would I create a GDK app with an activity stack?


Trying to get my head around how to do this and based on the examples it's not entirely clear. Let's say I wanted to modify the stopwatch app where the first screen is a screen saying "Do you want to start the stopwatch" then the menu activity would have a "Yes/No". Then when the user chooses "yes" the stopwatch starts, then if they swipe down the stopwatch goes away and it's back on the first screen.

I've gotten as far as the first screen with the Yes/No option. Can a push I push new activity/intent from the MenuActivity? When I want to show the stopwatch do I launch a new service? Or do I create a method in the existing service? Would I always be modifying the same live card or do I need separate live card instances for each screen? Thanks in advance for any help.


Solution

  • Activities on Glass work the same as they do on other Android devices. You can call startActivity or startActivityForResult to push a new activity onto the activity stack, you can call finish to dismiss an activity programmatically, and manipulate the stack in other ways.

    It sounds like the flow you're asking about is less about an activity stack though, and more about prompting the user before launching the service (because services must be used to publish live cards). If I'm understanding your question, you want something like this:

    1. Your voice trigger is assigned to an activity that displays a UI with the prompt "Do you want to start the stopwatch?"
    2. The activity overrides onCreateOptionsMenu to populate the menu with Yes/No options. (You don't need a separate menu activity when using a menu on an activity, only when attaching a menu to a live card.)
    3. You override onKeyDown or use a gesture detector to call openOptionsMenu when the user taps inside the activity.
    4. If the user taps Yes, you handle this inside onOptionsItemSelected and call startService to start the service, which then publishes the live card.
    5. Make sure to finish the activity so that it doesn't stick around after it's no longer needed.