I believe what you want is an ActionProvider.
You would specify an ActionProvider and that provider would implement whatever action you want such as launching an activity / sending an intent
문제
It would be great if I could specify which Activity to launch in the menu xml file, instead of having to override onOptionsItemSelected
for every class that uses this method. It seems there could be something that could be done to implement this a bit more elegantly. Are there any solutions that can achieve this?
해결책
I believe what you want is an ActionProvider.
You would specify an ActionProvider and that provider would implement whatever action you want such as launching an activity / sending an intent
다른 팁
You could override onOptionsItemSelected
in your base activity
public class MyActivity extends Activity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_launch_settings:
//TODO Launch settings
return true;
}
return super.onOptionsItemSelected(item);
}
}
Then in every menu.xml
file that you want to launch Setting include the action_launch_settings
item
<item
android:id="@+id/action_launch_settings"
android:title="Launch Settings"
/>