The easiest way of adding menu items (to specify the options menu for an activity) is inflating an XML file into the Menu via MenuInflater. With menu_main.xml we can do it in this way:
A. override fun onCreateOptionsMenu(menu: Menu): Boolean {menuInflater.inflate(R.menu.menu_main, menu)
return true
}
return true
}
B. override fun onOptionsItemSelected(item: MenuItem): Boolean {menuInflater.inflate(R.menu.menu_main, menu)
return super.onOptionsItemSelected(item)
}
C. override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.menu.menu_main)
}
As an example. In an Activity we have our TimerViewModel object (extended ViewModel), named mTimerViewModel. mTimerViewModel.timer method returns a LiveData
A. mTimerViewModel!!.timer.value.toString().observe (Observer { aLong -> callAnyChangeUIMethodHere(aLong!!) })
B. mTimerViewModel!!.timer.observe (this, Observer { aLong -> callAnyChangeUIMethodHere(aLong!!) })
C. mTimerViewModel.observe (Observer { aLong -> callAnyChangeUIMethodHere(aLong!!) })
With a room database. When performing queries, you'll often want your app's UI to update automatically when the data changes. Can you use a return value of type LiveData in your query method description to achieve this?
A. Yes
B. No
By executing an allowMainThreadQueries() method to the room database builder RoomDatabase.Builder, we can:
A. set the database factory
B. handle database first time creation
C. handle database opening
D. disable the main thread query check for Room
In general, you should send an AccessibilityEvent whenever the content of your custom view changes. For example, if you are implementing a custom slider bar that allows a user to select a numeric value by pressing the left or right arrows, your custom view should emit an event of type TYPE_VIEW_TEXT_CHANGED whenever the slider value changes. Which one of the following sample codes demonstrates the use of the sendAccessibilityEvent() method to report this event.
A. @Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
boolean completed = super.dispatchPopulateAccessibilityEvent(event);
CharSequence text = getText();
if (!TextUtils.isEmpty(text)) {
event.getText().add(text);
return true;
}
return completed;
}
B. @Overridepublic boolean onKeyUp (int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
currentValue--;
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED);
return true;
}
...
}
C. @Overridepublic boolean onKeyUp (int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_ENTER) {
currentValue--;
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CONTEXT_CLICKED);
return true;
}
...
}
In our TeaViewModelclass, that extends ViewModel, we have such method:
public LiveData
An observer in our Activity (type of mViewModelvariable in example is TeaViewModel) is set in this way:
mViewModel.getTea().observe(this, this::displayTea);
What will be a correct displayTea method definition?
A. private void displayTea()
B. private void displayTea(Tea tea)
C. private void displayTea(LiveData
D. private void displayTea(LiveData
For example, our preferences.xmlfile was added by addPreferencesFromResource(R.xml.preferences). Our preferences.xmlfile contains such item:
In our Fragment, we can dynamically get current notification preference value in this way:
A. boolean isNotificationOn = PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean(getContext().getString(R.string.pref_notification_key),getContext().getResources().getBoolean(R.bool.pref_notification_default_value)
);
B. boolean isNotificationOn = PreferenceManager.getSharedPreferences(getContext()).getBoolean(getContext().getString(R.string.pref_notification_default_value),getContext().getString(R.string.pref_notification_key)
);
C. boolean isNotificationOn = PreferenceManager.getSharedPreferences(getContext()).getBoolean(getContext().getResources().getBoolean(R.bool.pref_notification_default_value),getContext().getString(R.string.pref_notification_key)
);
Assume that an app includes a default set of graphics and two other sets of graphics, each optimized for a different device setup:
res/drawable/
Contains default graphics. res/drawable-small-land-stylus/
Contains graphics optimized for use with a device that expects input from a stylus and has a QVGA low-density screen in landscape orientation. res/drawable-ja/
Contains graphics optimized for use with Japanese.
What happens if the app runs on a device that is configured to use Japanese and, at the same time, the device happens to be one that expects input from a stylus and has a QVGA low-density screen in landscape orientation?
A. Android loads graphics from res/drawable/
B. Android loads graphics from res/drawable-small-land-stylus/
C. Android loads graphics from res/drawable-ja/
Choose the most correct statement.
A. Android is a closed source, Linux-based software stack created for a wide array of devices and form factors.
B. Android is a closed source, Windows-based software stack created for a wide array of devices and form factors.
C. Android is an open source, Linux-based software stack created for a wide array of devices and form factors.
D. Android is an open source software stack created for a highly limited array of devices and form factors.
Which statement is most true about layout_constraintLeft_toRightOf and layout_constraintStart_toEndOf constraints ?
A. layout_constraintLeft_toRightOf is equal to layout_constraintStart_toEndOf in any case
B. layout_constraintLeft_toRightOf is equal to layout_constraintStart_toEndOf in case if user choose a language that uses right-to-left (RTL) scripts, such as Arabic or Hebrew, for their UI locale
C. layout_constraintLeft_toRightOf is equal to layout_constraintStart_toEndOf in case if user choose a language that uses left-to-right (LTR) scripts, such as English or French, for their UI locale
D. layout_constraintLeft_toRightOf works with horizontal axes and layout_constraintStart_toEndOf works with vertical axes