In my little app users can have a look at 'more information' or send me feedback when they click on the menu button (of the device) at every xml file of the app.
This is my code (when you click on the menu button):
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.impressum:
startActivity(new Intent (this, MoreInformation.class));
break;
case R.id.feedback:
/*
*
*/
break;
}
return super.onOptionsItemSelected(item);
}
Now I put the code into all java classes. This obviously works but I'd like to create a class (Let's call it isMenuButtonPressed.class
) which contains the code above and I'd like to remove the code above from all other java classes and just call isMenuButtonPressed.class
(in these java classes when the menu button was pressed). How can you do that? How do you pass the information on that the menu button was pressed? How do you receive it in the isMenuButtonPressed.class
?
Thanks!