I have one problem using ActivityGroup
. I have two activities inside an ActivityGroup
and both of them use a menu (overriding the onCreateOptionMenu and onOptionsItemSelected).
Well, the problem is that the second activity in the group doesn't show the menu when I press the menu Key. The first activity works fine showing the menu.
Any idea about this issue?
I have this code in child activity:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
boolean result = super.onCreateOptionsMenu(menu);
menu.add(0, MENU_REFRESH, 0, R.string.menu_refresh).setIcon(R.drawable.ic_menu_refresh);
return result;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case MENU_REFRESH:
Log.d(TAG,"REFRESH");
refresh();
return true;
}
return super.onOptionsItemSelected(item);
}
Another nice way of handling this is by using the ActivityGroup's LocalActivityManager. Get the local activity manager, get the current activity, and perform that activity's appropriate method:
public boolean onPrepareOptionsMenu(Menu menu) {
//super.onPrepareOptionsMenu(menu);
return getLocalActivityManager().getCurrentActivity()
.onCreateOptionsMenu(menu);
}
public boolean onCreateOptionsMenu(Menu menu) {
//super.onCreateOptionsMenu(menu);
return getLocalActivityManager().getCurrentActivity()
.onCreateOptionsMenu(menu);
}
public boolean onMenuItemSelected(int featureId, MenuItem item) {
//super.onMenuItemSelected(featureId, item);
return getLocalActivityManager().getCurrentActivity()
.onMenuItemSelected(featureId, item);
}
Note: using this strategy, you must not call super.onCreateOptionsMenu from the child activity- doing so causes a stack overflow exception. I'm not sure what the purpose of calling the superclass's on* methods, as I've omitted them and have seen no negative results. (... yet)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With