注意:类 ProcessingOptionMenu 将没有自己的布局。没有布局的类是否可以启动另一个活动,例如类 ProcessingOptionMenu 启动新活动 SettingABC
活动 A { ..
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.second_menu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
ProcessingOptionMenu objectMenu= new ProcessingOptionMenu();
boolean resultReturn=objectMenu.identifyItem(item);
}
..
}
Activity B {
..
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.second_menu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
ProcessingOptionMenu objectMenu= new ProcessingOptionMenu();
boolean resultReturn=objectMenu.identifyItem(item);
}
..
}
class ProcessingOptionMenu extends Activity {
public boolean identifyItem(MenuItem item) {
if (item.getItemId() == R.id.settingapp) {
Intent intentAppSetting = new Intent(ProcessingOptionMenu.this, SettingABC.class);
startActivity(intentAppSetting);
return true;
}
return false;
}
}