Google Associate Android Developer - Associate Android Developer Exam
Page: 2 / 22
Total 107 questions
Question #6 (Topic: Single Topic)
Android Tests. You can use the childSelector() method to nest multiple UiSelector instances. For example, the following code example shows how your test
might specify a search to find the first ListView in the currently displayed UI, then search within that ListView to find a UI element with the text property Apps. What
is the correct sample?
might specify a search to find the first ListView in the currently displayed UI, then search within that ListView to find a UI element with the text property Apps. What
is the correct sample?
A. val appItem: UiObject = device.findObject( UiSelector().className(ListView.class) .instance(1) .childSelector( UiSelector().text("Apps") ) )
B. val appItem: UiObject = device.findObject( UiSelector().className("android.widget.ListView") .instance(0) .childSelector( UiSelector().text("Apps") ) )
C. val appItem: UiObject = device.findObject( UiSelector().className("android.widget.ListView") .instance( UiSelector().text("Apps") ) )
Answer: B
Question #7 (Topic: Single Topic)
The following code snippet shows an example of an Espresso test:
A. @Rule fun greeterSaysHello() { onView(withId(R.id.name_field)).do(typeText("Steve")) onView(withId(R.id.greet_button)).do(click()) onView(withText("Hello Steve!")).check(matches(isDisplayed())) }
B. @Test fun greeterSaysHello() { onView(withId(R.id.name_field)).perform(typeText("Steve")) onView(withId(R.id.greet_button)).perform(click()) onView(withText("Hello Steve!")).check(matches(isDisplayed())) }
C. @Test fun greeterSaysHello() { onView(withId(R.id.name_field)).do(typeText("Steve")) onView(withId(R.id.greet_button)).do(click()) onView(withText("Hello Steve!")).compare(matches(isDisplayed())) }
Answer: B
Question #8 (Topic: Single Topic)
As an example. In an Activity we have our TimerViewModel object (extended ViewModel), named mTimerViewModel. mTimerViewModel.timer
method returns a LiveData<Long> value. What can be a correct way to set an observer to change UI in case if data was changed?
method returns a LiveData<Long> value. What can be a correct way to set an observer to change UI in case if data was changed?
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!!) })
Answer: B
Question #9 (Topic: Single Topic)
LiveData.postValue() and LiveData.setValue() methods have some differences. So if you have a following code executed in the main thread:
liveData.postValue("a");
liveData.setValue("b");
What will be the correct statement?
liveData.postValue("a");
liveData.setValue("b");
What will be the correct statement?
A. The value "b" would be set at first and later the main thread would override it with the value "a".
B. The value "a" would be set at first and later the main thread would override it with the value "b".
C. The value "b" would be set at first and would not be overridden with the value "a".
D. The value "a" would be set at first and would not be overridden with the value "b".
Answer: B
Question #10 (Topic: Single Topic)
In our TeaViewModel class, that extends ViewModel, we have such prorerty:
val tea: LiveData<Tea>
An observer in our Activity (type of mViewModel variable in example is TeaViewModel) is set in this way:
mViewModel!!.tea.observe(this, Observer { tea: Tea? -> displayTea(tea) })
What will be a correct displayTea method definition?
val tea: LiveData<Tea>
An observer in our Activity (type of mViewModel variable in example is TeaViewModel) is set in this way:
mViewModel!!.tea.observe(this, Observer { tea: Tea? -> displayTea(tea) })
What will be a correct displayTea method definition?
A. private fun displayTea()
B. private fun displayTea(tea: Tea?)
C. private fun displayTea(tea: LiveData?<Tea>)
D. private fun displayTea(tea: LiveData?<T>)
Answer: B