0

I am writing a simple app for Google Glass. There are three activities which each handle a static card. Each card has its own menu. Now I read on google developer that swiping down should work like the back button on android smartphones, i.e. call the last activity from the stack. Now my problem is that this only works for the 'launcher' activity.

ok-glass menu -> activity_1 -> ok-glass menu works fine, but activity_1 -> activity_2 -> activity_1 does not. Same goes for activity_3. If however activity_1 is called from activity_3 swiping down behaves as intended. (activity_3 -> activity_1 -> activity_3 works).

Also, swipe down works in menus in all activities.

Now I have a couple of questions:

  1. Is the approach to use a seperate activity for each card the right one?
  2. Should user input be handled in the onKeyDown method or in an onClicklistener?
  3. Is it necessary to override the swipe down gesture for it to work the way intended (going back to the last activity)?
  4. Unrelated: All my menus contain only one option, which is used as a kind of acknowlegdement by the user that he wants to continue. (i.e. call the next activity). Is this best practice?

I spent 3 hours searching the internet on this issue. I tried calling super.onBackPressed, implementing various types of listeners and using the setFocusMethod on the views. Any suggestions on how to get this to work consistently across the app are greatly appreciated. Thanks in advance!

Below you can find the code for one of these activities which looks similar across all three.

public class Test1Activity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    View test1 = new CardBuilder(getBaseContext(), CardBuilder.Layout.CAPTION)
        .setText("test1")
        .getView();

    setContentView(test1);
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
    if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
        openOptionsMenu();
        return true;
    }
    return false;
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.test1, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item)
{
    switch (item.getItemId()) {
        case R.id.test1_ack:
            Intent intent = new Intent(this, Test2Activity.class);
            startActivity(intent);
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
}
pt2121
  • 11,720
  • 8
  • 52
  • 69
schlingel
  • 3
  • 3

1 Answers1

2
  1. Is the approach to use a separate activity for each card the right one?

It depends. In Android, an activity represents a single, focused thing that the user can do. So, if your activities/cards are not related, it's ok. If they are, you can group cards together in one activity using CardScrollView. http://developer.android.com/training/design-navigation/descendant-lateral.html might also be helpful. (It explains how you can group information together.)

  1. Should user input be handled in the onKeyDown method or in an onClicklistener?

You should use GestureDetector. See https://developers.google.com/glass/develop/gdk/touch. onKeyDown has limited functionality because it's not designed for Glass. I might be wrong but I think you can only detect tap with onKeyDown.

  1. Is it necessary to override the swipe down gesture for it to work the way intended (going back to the last activity)?

It's a default behavior (No Flag). If you don't call finish() on activity 1 when starting activity 2, you should be able to go back without overriding any methods. Please see : Android: Go back to previous activity. You can also use android:parentActivityName tag in the manifest to specify a parent activity. (http://developer.android.com/guide/topics/manifest/activity-element.html)

  1. Unrelated: All my menus contain only one option, which is used as a kind of acknowledgement by the user that he wants to continue. (i.e. call the next activity). Is this best practice?

It's kinda weird but nothing wrong with that. Anyway, you don't need acknowledgement every time when a user does something. I'm not a UX designer but I notice from build-in apps that on Glass a confirmation/acknowledgement screen is not quite common. For example, when you are sending sms, there is no confirmation dialog. I guess the design team try to get rid of unnecessary interactions. Try to make a menu represents an action so a user goes forward/ or does something on each tap.

See also https://developers.google.com/glass/tools-downloads/glassware-flow-designer.

Note: I am no expert on UX design so don't trust me :)

You can check out my example on GitHub. I implemented the flow showed below.

flow

Community
  • 1
  • 1
pt2121
  • 11,720
  • 8
  • 52
  • 69
  • Thank you very much for taking the time to answer this detailed. Unfortunately I didn't have the time to continue with this project and ended up creating a new one from scratch. This also resolved the aformentioned problems. Your reply helped me understand the flow of Glass apps however. – schlingel Oct 12 '14 at 12:58