Reputation: 19848
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?
Upvotes: 0
Views: 113
Reputation: 21733
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
Upvotes: 1
Reputation: 623
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"
/>
Upvotes: 0