You can can create a "BaseActivity" and include a lot code in that single class and then simply create classes and extend that "BaseActivity".
Here is what I think you are looking for:
public class BaseActivity extends Activity {
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case R.id.donate:
//something
break;
case R.id.about_menuitem:
//something
break;
case R.id.exit:
finish();
break;
default:
return true;
}
return true;
}
}
I created a class called "BaseActivity", in this class I have my Android options menu and I also extend "Activity". Since I extended "Activity" and have my options menu in this class, I can now use this same menu code for all my other classes.
I just simply create my new classes and extend them with "BaseActivity":
public class SomeOtherActivity extends BaseActivity {
//new code here
}
Now the class called "SomeOtherActivity", will inherit my menu code and also "Activity".
Please try this out and let me know is this helps!