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:
- Is the approach to use a seperate activity for each card the right one?
- Should user input be handled in the
onKeyDown
method or in anonClicklistener
? - Is it necessary to override the swipe down gesture for it to work the way intended (going back to the last activity)?
- 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);
}
}
}