Premium

Associate Android Developer Certification Questions and Answer (Dumps and Practice Questions)



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

 : What two methods you have to override when implementing Android option menus?
1. onCreateOptionsMenu, onCreateContextMenu

2. onCreateContextMenu, onContextItemSelected

3. onCreateOptionsMenu, onOptionsItemSelected

4. onCreateOptionsMenu, onContextItemSelected

Correct Answer : 3
Explanation: Android Option Menus are the primary menus of android. They can be used for settings, search, delete item etc.
To perform event handling on menu items, you need to override onOptionsItemSelected() method of Activity class.

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;
}




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

 : 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

Correct Answer : 4
Explanation: You can declare items for the options menu from either your Activity subclass or a Fragment subclass. If both your activity and fragment(s) declare items for the options menu, they are combined in the UI. The activity's items appear first, followed by those of each fragment in the order in which each fragment is added to the activity. If necessary, you can re-order the menu items with the android:orderInCategory attribute in each you need to move.

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;
}
You can also add menu items using add() and retrieve items with findItem() to revise their properties with MenuItem APIs.




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

 : 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

Correct Answer : 4
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. 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) {
// Handle item selection
switch (item.getItemId()) {
case R.id.new_game:
newGame();
return true;
case R.id.help:
showHelp();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
When you successfully handle a menu item, return true. If you don't handle the menu item, you should call the superclass implementation of onOptionsItemSelected() (the default implementation returns false).

If your activity includes fragments, the system first calls onOptionsItemSelected() for the activity then for each fragment (in the order each fragment was added) until one returns true or all fragments have been called.


Related Questions


Question : Which package of the following does not have classes needed for Android network connections?

 : Which package of the following does not have classes needed for Android network connections?
1. java.net

2. org.apache.http

3. Access Mostly Uused Products by 50000+ Subscribers

4. android.net


Question : Which of the following tools creates certificates for signing Android applications?

 : Which of the following tools creates certificates for signing Android applications?
1. adb

2. logcat

3. Access Mostly Uused Products by 50000+ Subscribers

4. certgen


Question : Which manifest file permission you should add to allow your application to read the device's address book?

 : Which manifest file permission you should add to allow your application to read the device's address book?
1. READ_ADDRESS_DATA

2. READ_PHONE_STATE

3. Access Mostly Uused Products by 50000+ Subscribers

4. READ_CONTACTS


Question : You can create a custom view by extending class:

 : You can create a custom view by extending class:
1. android.widget.View

2. android.widget.LinearLayout

3. Access Mostly Uused Products by 50000+ Subscribers

4. android.content.Context


Question : In which Activity life-cycle method you should do all of your normal static set up such as: creating views and bind data to lists?

 : In which Activity life-cycle method you should do all of your normal static set up such as: creating views and bind data to lists?
1. onResume()

2. onStart()

3. Access Mostly Uused Products by 50000+ Subscribers

4. onPause()


Question : Which of the following lines of code starts activity Activity from a current activity Activity?
 : Which of the following lines of code starts activity Activity from a current activity Activity?
1. Intent intent = new Intent(this,new Activity2());
startActivity(intent);

2. Intent intent = new Intent(new Activity2());
startActivity(intent);

3. Access Mostly Uused Products by 50000+ Subscribers
startActivity(intent);

4. Intent intent = new Intent(this,Activity2.class);
startActivity(intent);