I have an activity for my menu events:
public class GlobalMenu extends Activity{
private MenuItem item;
public boolean event(MenuItem item){
this.item = item;
// Handle item selection
switch (this.item.getItemId()) {
case R.id.menu_stop:
finish();
return true;
}
return true;
}
}
And I use it like this
GlobalMenu gm = new GlobalMenu();
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return gm.event(item);
}
But the finish didn’t work, I think I need to link it with an application but I don’t know how to do
Thanks
First of All, You can’t make a Object or Instance of Android Activity.
like this
You have to pass a Context of GlobalMenu Activity to other Activity or Class and then call finish on this.
Like,
Here mContext is a reference of
GlobalMenu Activity.