Android AND-401 Exam Questions
Android Application Development (Page 8 )

Updated On: 24-Feb-2026

What two methods you have to override when implementing Android context menus?

  1. onCreateOptionsMenu, onCreateContextMenu
  2. onCreateContextMenu, onContextItemSelected
  3. onCreateOptionsMenu, onOptionsItemSelected
  4. onCreateOptionsMenu, onContextItemSelected

Answer(s): B

Explanation:

Need to create context menu. For this need to override this method:
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle("My Context Menu");
menu.add(0, NEW_MENU_ITEM, 0, "new");
menu.add(0, SAVE_MENU_ITEM, 1, "save");
}
And last one need to handle menu clicks:
@Override
public boolean onContextItemSelected(MenuItem item) {
switch (item.getItemId()) {
case NEW_MENU_ITEM:
doSomething();
break;
case SAVE_MENU_ITEM:
doSomething();
break;
}
return super.onContextItemSelected(item);
}


Reference:

https://thedevelopersinfo.wordpress.com/2009/11/06/using-context-menus-in-android/



What two methods you have to override when implementing Android option menus?

  1. onCreateOptionsMenu, onCreateContextMenu
  2. onCreateContextMenu, onContextItemSelected
  3. onCreateOptionsMenu, onOptionsItemSelected
  4. onCreateOptionsMenu, onContextItemSelected

Answer(s): C

Explanation:

To specify the options menu for an activity, override onCreateOptionsMenu().
When the user selects an item from the options menu (including action items in the app bar), the system calls your activity's onOptionsItemSelected() method. This method passes the MenuItem selected. You can identify the item by calling getItemId(), which returns the unique ID for the menu item (defined by the android:id attribute in the menu resource or with an integer given to the add() method). You can match this ID against known menu items to perform the appropriate action.
For example:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Etc.


Reference:

http://developer.android.com/guide/topics/ui/menus.html



Which of the following is a call-back method that inflates an options menu from file res/menu/menu.xml?

  1. onOptionsItemSelected
  2. onCreate
  3. onCreateMenu
  4. onCreateOptionsMenu

Answer(s): D

Explanation:

To specify the options menu for an activity, override onCreateOptionsMenu() (fragments provide their own onCreateOptionsMenu() callback). In this method, you can inflate your menu resource (defined in XML) into the Menu provided in the callback. For example:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.game_menu, menu);
return true;
}


Reference:

http://developer.android.com/guide/topics/ui/menus.html



Which of the following Activity methods is invoked when the user clicks on an options menu item?

  1. onItemClicked
  2. onItemSelected
  3. onOptionsItemClicked
  4. onOptionsItemSelected

Answer(s): D

Explanation:

When the user selects an item from the options menu (including action items in the app bar), the system calls your activity's onOptionsItemSelected() method.


Reference:

http://developer.android.com/guide/topics/ui/menus.html



Which of the following WebView methods allows you to manually load custom HTML markup?

  1. loadData
  2. loadHTML
  3. loadCustomData
  4. loadCustomHTML

Answer(s): A

Explanation:

Example: To load the desired web page from an HTML string:
String summary = "<html><body>You scored <b>192</b> points.</body></html>"; webview.loadData(summary, "text/html", null);


Reference:

http://developer.android.com/reference/android/webkit/WebView.html






Post your Comments and Discuss Android AND-401 exam dumps with other Community members:

Join the AND-401 Discussion