Black Friday Special Limited Time 70% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: 70percent

Google Associate-Android-Developer Google Developers Certification - Associate Android Developer (Kotlin and Java Exam) Exam Practice Test

Google Developers Certification - Associate Android Developer (Kotlin and Java Exam) Questions and Answers

Question 1

We have a custom view that extends android.widget.ProgressBar. Our progress bar is not touchable, focusable, etc.: it just shows progress. Style for our custom progress bar extends

“Widget.AppCompat.ProgressBar.Horizontal”. An item, named “progressDrawable”, in our style, is a xml file . What we usually can see as a main single element in this xml file:

Options:

A.

A State List ( element )

B.

A Layer List ( element) with items android:id="@+id/progress" and android:id="@+id/ background" inside it.

C.

An element with android:id="@+id/progress" identifier

Question 2

Custom views and directional controller clicks. On most devices, clicking a view using a directional controller sends (to the view currently in focus) a KeyEvent with:

Options:

A.

KEYCODE_DPAD_CENTER

B.

KEYCODE_BUTTON_START

C.

KEYCODE_CALL

D.

KEYCODE_BUTTON_SELECT

Question 3

Move the major components of the Android platform to correct places in diagram.

Options:

Question 4

Building your app from the command line, if you have a "demo" product flavor, then you can build the debug version with the command:

Options:

A.

gradlew assembleDemoDebug

B.

gradlew installDemoDebug

C.

both variants are correct.

Question 5

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.

Options:

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.

@Override

public boolean onKeyUp (int keyCode, KeyEvent event) {

if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {

currentValue--;

sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED);

return true;

}

...

}

C.

@Override

public boolean onKeyUp (int keyCode, KeyEvent event) {

if (keyCode == KeyEvent.KEYCODE_ENTER) {

currentValue--;

sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CONTEXT_CLICKED);

return true;

}

...

}

Question 6

Custom views and directional controller clicks. In general, you should send an AccessibilityEvent whenever the content of your custom view changes. For example, if a text value was changed in your custom view, you should emit an event of this type:

Options:

A.

TYPE_WINDOWS_CHANGED

B.

TYPE_VIEW_CONTEXT_CLICKED

C.

TYPE_WINDOWS_CHANGED

D.

TYPE_VIEW_TEXT_CHANGED

Question 7

Custom duration in milliseconds as a parameter for the setDuration method is available when you are working with:

Options:

A.

Toast

B.

Snackbar

C.

for none of them

D.

for both of them

Question 8

Working with Custom View. Once you define the custom attributes, you can use them in layout XML files just like built-in attributes. The only difference is that your custom attributes belong to a different namespace. Instead of belonging to the http://schemas.android.com/apk/res/android namespace, they belong to:

Options:

A.

http://schemas.android.com/apk/res/[your package name]

B.

http://schemas.android.com/apk/[your package name]

C.

http://schemas.android.com/[your package name]

Question 9

For example, we have a file in our assets folder app/src/main/assets/sample_teas.json. To get an

InputStream for reading it, from out Context context, we can try doing this:

Options:

A.

InputStream input = context.getResources().openRawResource(R.raw.sample_teas);

B.

InputStream input = context.getAssets().open("sample_teas.json");

C.

InputStream input = context.getResources().getAssets().open ("sample_teas.json");

Question 10

In a class PreferenceFragmentCompat. As a convenience, this fragment implements a click listener for any preference in the current hierarchy. So, in what overridden method we can handle that a preference in the tree rooted at this PreferenceScreen has been clicked?

Options:

A.

onCreateLayoutManager

B.

onCreatePreferences

C.

onCreateRecyclerView

D.

onPreferenceTreeClick

Question 11

What is demonstrated by the code below?

// RawDao.kt

@Dao

interface RawDao {

@RawQuery

fun getUserViaQuery(query: SupportSQLiteQuery?): User?

}

// Usage of RawDao

...

val query =

SimpleSQLiteQuery("SELECT * FROM User WHERE id = ? LIMIT 1",

arrayOf(sortBy))

val user = rawDao.getUserViaQuery(query)

...

Options:

A.

A method in a Dao annotated class as a raw query method where you can pass the query as a

SupportSQLiteQuery.

B.

A method in a Dao annotated class as a query method.

C.

A method in a RoomDatabase class as a query method.

Question 12

What statements about InputStreamReader (java.io.InputStreamReader) are correct? (Choose two.)

Options:

A.

An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes them into characters using a specified charset. The charset that it uses may be specified by name or may be given explicitly, or the platform's default charset may be accepted.

B.

An InputStreamReader is a bridge from character streams to byte streams: It reads characters using a specified charset and encodes them into bytes. The charset that it uses may be specified by name or may be given explicitly, or the platform's default charset may be accepted.

C.

Each invocation of one of an InputStreamReader's read() methods may cause one or more bytes to be read from the underlying byte-input stream. To enable the efficient conversion of bytes to characters, more bytes may be read ahead from the underlying stream than are necessary to satisfy the current read operation.

D.

No any invocation of one of an InputStreamReader's read() methods can cause some bytes to be read from the underlying byte-input stream.

Question 13

An example. In our ViewModelFactory (that implements ViewModelProvider.Factory) we have an instance of our Repository, named mRepository. Our ViewModel has such constructor:

class MyViewModel(private val mRepository: MyRepository) : ViewModel() ...

Next, in our ViewModelFactory create ViewModel method (overriden) looks like this:

override fun create(modelClass: Class): T {

return try {

//MISSED RETURN VALUE HERE”

} catch (e: InstantiationException) {

throw RuntimeException("Cannot create an instance of $modelClass", e)

} catch (e: IllegalAccessException) {

throw RuntimeException("Cannot create an instance of $modelClass", e)

} catch (e: NoSuchMethodException) {

throw RuntimeException("Cannot create an instance of $modelClass", e)

} catch (e: InvocationTargetException) {

throw RuntimeException("Cannot create an instance of $modelClass", e)

}

}

What should we write instead of “//MISSED RETURN VALUE HERE”?

Options:

A.

modelClass.getConstructor()

.newInstance(mRepository)

B.

modelClass.getConstructor(MyRepository::class.java)

.newInstance()

C.

modelClass.getConstructor(MyRepository::class.java)

.newInstance(mRepository)

Question 14

In our TeaViewModel class, that extends ViewModel, we have such prorerty:

val tea: LiveData

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?

Options:

A.

private fun displayTea()

B.

private fun displayTea(tea: Tea?)

C.

private fun displayTea(tea: LiveData?)

D.

private fun displayTea(tea: LiveData?)

Question 15

What is the incorrect statement about Data Access Object (androidx.room.Dao)?

Options:

A.

Data Access Objects are the main classes where you define your database interactions. They can include a variety of query methods.

B.

The class marked with @Dao should either be an interface or an abstract class. At compile time, Room will

generate an implementation of this class when it is referenced by a Database.

C.

An abstract @Dao class can optionally have a constructor that takes a Database as its only parameter.

D.

It is recommended to have only one Dao class in your codebase for all tables.

Question 16

Enable debugging on your device: If you are using the emulator, this is enabled by default. But for a connected device, you need to

Options:

A.

enable transfer data from the device in usb connection options.

B.

enable debugging in the device developer options.

C.

enable connection in bluetooth options.

Question 17

Once your test has obtained a UiObject object, you can call the methods in the UiObject class to perform user interactions on the UI component represented by that object. You can specify such actions as: (Choose four.)

Options:

A.

click() : Clicks the center of the visible bounds of the UI element.

B.

touch() : Touch the center of the visible bounds of the UI element.

C.

dragTo() : Drags this object to arbitrary coordinates.

D.

moveTo() : Move this object to arbitrary coordinates.

E.

setText() : Sets the text in an editable field, after clearing the field's content. Conversely, the

clearTextField() method clears the existing text in an editable field.

F.

swipeUp() : Performs the swipe up action on the UiObject. Similarly, the swipeDown(), swipeLeft(), and swipeRight() methods perform corresponding actions.

Question 18

What happens when you create a DAO method and annotate it with @Insert?

Example:

@Dao

interface MyDao {

@Insert(onConflict = OnConflictStrategy.REPLACE)

fun insertUsers(vararg users: User)

}

Options:

A.

Room generates an implementation that inserts all parameters into the database in a single transaction.

B.

Room modifies a set of entities, given as parameters, in the database. It uses a query that matches against the primary key of each entity.

C.

Room removes a set of entities, given as parameters, from the database. It uses the primary keys to find the entities to delete.