1

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.

1 Answer 1

2

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.
1
  • I tried this and it worked great. I have a couple more questions now though. If I change this where it opens another activity when I select a menu item then I can use the back motion to dismiss the second activity to go back to the first. When I start the stopwatch service however from the root activity menu the back motion closes the app. When I select "Stop" in the menu of the service then it kills the app entirely. How should I stop the service and go back to the activity that started it? Also how do I play that satisfying "ca-chick" sound when I openOptionsMenu()? thanks.
    – Pickles
    Jan 6, 2014 at 21:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.