Reputation: 6852
How can I populate a menu using intents? I didn't understand that thing.
Or is there any better way for that?
Suppose I have an application that need to resize the image,and there are many other applications that have a capability of resizing the image. How can I show the list of applications on a menu in my application so that when clicking on a particular option it will invoke the intent associated with that application. Simply saying I could resize the image in my application with out bothering about how that will get done.
Upvotes: 0
Views: 321
Reputation: 7722
Here you have an example, using the onOptionsItemSelected that appears with the menu button you control what the menu does:
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case HISTORY_ID: {
AlertDialog historyAlert = historyManager.buildAlert();
historyAlert.show();
break;
}
case SETTINGS_ID: {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
intent.setClassName(this, PreferencesActivity.class.getName());
startActivity(intent);
break;
}
}
But we create the menu with this code:
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, SETTINGS_ID, 0, R.string.menu_settings)
.setIcon(android.R.drawable.ic_menu_preferences);
menu.add(0, HELP_ID, 0, R.string.menu_help)
.setIcon(android.R.drawable.ic_menu_help);
menu.add(0, ABOUT_ID, 0, R.string.menu_about)
.setIcon(android.R.drawable.ic_menu_info_details);
return true;
}
Upvotes: 1