Google Associate Android Developer Exam Dumps - Practice Questions - Post 45

#Advertisement

Google Associate Android Developer Exam Dumps - Practice Questions - Post 45

1. What is a correct part of an Implicit Intent for sharing data implementation?

Page: Page 1

Option A: val sendIntent = Intent(this, UploadService::class.java).apply { putExtra(Intent.EXTRA_TEXT, textMessage) ...

Option B: val sendIntent = Intent().apply { type = Intent.ACTION_SEND; ...

Option C: val sendIntent = Intent(this, UploadService::class.java).apply { data = Uri.parse(fileUrl) ...

Option D: val sendIntent = Intent().apply { action = Intent.ACTION_SEND ...

Answer(s): 4

Explanation: Create the text message with a string val sendIntent = Intent().apply { action = Intent.ACTION_SEND putExtra(Intent.EXTRA_TEXT, textMessage) type = "text/plain" }

SEO Keywords: SEO keywords not available


2. By default, the notification's text content is truncated to fit one line. If you want your notification to be longer, for example, to create a larger text area, you can do it in this way:

Page: Page 1

Option A: var builder = NotificationCompat.Builder(this, CHANNEL_ID) .setContentText("Much longer text that cannot fit one line...") .setStyle(NotificationCompat.BigTextStyle() .bigText("Much longer text that cannot fit one line...")) ...

Option B: var builder = NotificationCompat.Builder(this, CHANNEL_ID) .setContentText("Much longer text that cannot fit one line...") .setLongText("Much longer text that cannot fit one line...")) ...

Option C: var builder = NotificationCompat.Builder(this, CHANNEL_ID) .setContentText("Much longer text that cannot fit one line...") .setTheme(android.R.style.Theme_LongText); ...

Answer(s): 1

Explanation: https://developer.android.com/training/notify-user/build-notification

SEO Keywords: SEO keywords not available


3. Select correct demonstration of WorkRequest cancellation.

Page: Page 1

Option A: workManager.enqueue(OneTimeWorkRequest.Builder(FooWorker::class.java).build())

Option B: val request: WorkRequest = OneTimeWorkRequest.Builder(FooWorker::class.java).build() workManager.enqueue(request) val status = workManager.getWorkInfoByIdLiveData(request.id) status.observe(...)

Option C: val request: WorkRequest = OneTimeWorkRequest.Builder(FooWorker::class.java).build() workManager.enqueue(request) workManager.cancelWorkById(request.id)

Option D: val request1: WorkRequest = OneTimeWorkRequest.Builder(FooWorker::class.java).build() val request2: WorkRequest = OneTimeWorkRequest.Builder(BarWorker::class.java).build() val request3: WorkRequest = OneTimeWorkRequest.Builder(BazWorker::class.java).build() workManager.beginWith(request1, request2).then(request3).enqueue()

Answer(s): 3

Explanation: Videos: -Working with WorkManager, from the 2018 Android Dev Summit -WorkManager: Beyond the basics, from the 2019 Android Dev Summit

SEO Keywords: SEO keywords not available


4. 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.

Page: Page 1

Option A: override fun dispatchPopulateAccessibilityEvent(event: AccessibilityEvent): Boolean { return super.dispatchPopulateAccessibilityEvent(event).let { completed -> if (text?.isNotEmpty() == true) { event.text.add(text) true } else { completed } } }

Option B: override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean { return when(keyCode) { KeyEvent.KEYCODE_DPAD_LEFT -> { currentValue-- sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED) true } ... } }

Option C: override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean { return when(keyCode) { KeyEvent.KEYCODE_ENTER -> { currentValue-- sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CONTEXT_CLICKED) true } ... } }

Answer(s): 2

Explanation: https://developer.android.com/guide/topics/ui/accessibility/custom-views

SEO Keywords: SEO keywords not available


5. 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?

Page: Page 2

Option A: The value "b" would be set at first and later the main thread would override it with the value "a".

Option B: The value "a" would be set at first and later the main thread would override it with the value "b".

Option C: The value "b" would be set at first and would not be overridden with the value "a".

Option D: The value "a" would be set at first and would not be overridden with the value "b".

Answer(s): 2

Explanation: Not available

SEO Keywords: SEO keywords not available


6. 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?

Page: Page 2

Option A: private fun displayTea()

Option B: private fun displayTea(tea: Tea?)

Option C: private fun displayTea(tea: LiveData?)

Option D: private fun displayTea(tea: LiveData?)

Answer(s): 2

Explanation: Not available

SEO Keywords: SEO keywords not available


7. For example, our preferences.xml file was added by addPreferencesFromResource (R.xml.preferences). Our preferences.xml file contains such item: In our Fragment, we can dynamically get current notification preference value in this way:

Page: Page 2

Option A: val isNotificationOn = PreferenceManager.getDefaultSharedPreferences(context).getBoolean( context!!.getString(R.string.pref_notification_key), context!!.resources.getBoolean(R.bool.pref_notification_default_value) )

Option B: val isNotificationOn = PreferenceManager.getSharedPreferences(context).getBoolean( context!!.getString(R.string.pref_notification_default_value), context!!.getString(R.string.pref_notification_key), )

Option C: val isNotificationOn = PreferenceManager.getSharedPreferences(context).getBoolean( context!!.resources.getBoolean(R.bool.pref_notification_default_value), context!!.getString(R.string.pref_notification_key) )

Answer(s): 1

Explanation: Not available

SEO Keywords: SEO keywords not available


8. For example, our preferences.xml file was added by addPreferencesFromResource (R.xml.preferences). Our preferences.xml file contains such item: In our Fragment, we can dynamically get current notification preference value in this way:

Page: Page 2

Option A: val sortBy = PreferenceManager.getDefaultSharedPreferences(context).getString( context!!.getString(R.string.pref_sort_key), context!!.resources.getBoolean(R.bool.pref_default_sort_value) )

Option B: val sortBy = PreferenceManager.getSharedPreferences(context).getString( context!!.getString(R.string.pref_default_sort_value), context!!.getString(R.string.pref_sort_key), )

Option C: val sortBy = PreferenceManager.getSharedPreferences(context).getBoolean( context!!.resources.getBoolean(R.bool.pref_default_sort_value), context!!.getString(R.string.pref_sort_key) )

Option D: val sortBy = PreferenceManager.getDefaultSharedPreferences(context).getString( context!!.getString(R.string.pref_sort_key), context!!.getString(R.string.pref_default_sort_value) )

Answer(s): 4

Explanation: Not available

SEO Keywords: SEO keywords not available


9. For example, we have a file in our raw folder app/src/main/res/raw/sample_teas.json. To get an InputStream for reading it, from out Context context, we can do this:

Page: Page 3

Option A: val input = context!!.openRawResource(R.raw.sample_teas)

Option B: val input = context!!.getRawResource(R.raw.sample_teas)

Option C: val input = context!!.resources.openRawResource(R.raw.sample_teas)

Answer(s):

Explanation: Not available

SEO Keywords: SEO keywords not available


10. For example, we have a BufferedReader reader, associated with the json file through InputStreamReader. To get a file data we can do this:

Page: Page 3

Option A: var line: String? try { while (reader.readLine().also { line = it } != null) { builder.append(line) } val json = JSONObject(builder.toString()) return json } catch (exception: IOException) { exception.printStackTrace() } catch (exception: JSONException) { exception.printStackTrace() }

Option B: var line: JSONObject ? try { while (reader.readJSONObject ().also { line = it } != null) { builder.append(line) } val json = JSONObject(builder.toString()) return json } catch (exception: IOException) { exception.printStackTrace() } catch (exception: JSONException) { exception.printStackTrace() }

Option C: var line: String? try { while (reader.readLine().also { line = it } != null) { builder.append(line) } val json = JSONObject(builder.toString()) return json } catch (exception: RuntimeException) { exception.printStackTrace() } catch (exception: ArrayIndexOutOfBoundsException) { exception.printStackTrace() }

Answer(s):

Explanation: Not available

SEO Keywords: SEO keywords not available


11. 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 do this:

Page: Page 3

Option A: val input = context!!.resources.openRawResource(R.raw.sample_teas)

Option B: val input = context!!.assets.open("sample_teas.json")

Option C: val input = context!!.resources.assets.open("sample_teas.json")

Answer(s):

Explanation: Not available

SEO Keywords: SEO keywords not available


12. 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”?

Page: Page 3

Option A: modelClass.getConstructor() .newInstance(mRepository)

Option B: modelClass.getConstructor(MyRepository::class.java) .newInstance()

Option C: modelClass.getConstructor(MyRepository::class.java) .newInstance(mRepository)

Answer(s):

Explanation: Not available

SEO Keywords: SEO keywords not available


13. 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) ...

Page: Page 4

Option A: A method in a Dao annotated class as a raw query method where you can pass the query as a SupportSQLiteQuery.

Option B: A method in a Dao annotated class as a query method.

Option C: A method in a RoomDatabase class as a query method.

Answer(s):

Explanation: Not available

SEO Keywords: SEO keywords not available


14. 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) }

Page: Page 4

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

Option 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.

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

Answer(s):

Explanation: Not available

SEO Keywords: SEO keywords not available


15. What do you want from Room when you create a DAO method and annotate it with @Update? Example: @Dao interface MyDao { @Update fun updateUsers(vararg users: User) }

Page: Page 4

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

Option 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.

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

Answer(s):

Explanation: Not available

SEO Keywords: SEO keywords not available


16. What do you want from Room when you create a DAO method and annotate it with @Delete? Example: @Dao interface MyDao { @Delete fun deleteUsers(vararg users: User) }

Page: Page 4

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

Option 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.

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

Answer(s):

Explanation: Not available

SEO Keywords: SEO keywords not available


17. To automate UI tests with Android Studio, you implement your test code in a separate Android test folder. Folder could be named:

Page: Page 5

Option A: app/androidTest/java

Option B: app/src/androidTest/java

Option C: app/java/androidTest

Answer(s):

Explanation: Not available

SEO Keywords: SEO keywords not available


18. 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.)

Page: Page 5

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

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

Option C: dragTo() : Drags this object to arbitrary coordinates.

Option D: moveTo() : Move this object to arbitrary coordinates.

Answer(s):

Explanation: Not available

SEO Keywords: SEO keywords not available


19. If you want to access a specific UI component in an app, use the UiSelector class. This class represents a query for specific elements in the currently displayed UI. What is correct about it? (Choose two.)

Page: Page 5

Option A: If more than one matching element is found, the first matching element in the layout hierarchy is returned as the target UiObject.

Option B: If no matching UI element is found, an IOException is thrown.

Option C: If more than one matching element is found, the last matching element in the layout hierarchy is returned as the target UiObject.

Option D: If no matching UI element is found, a UiAutomatorObjectNotFoundException is thrown.

Answer(s):

Explanation: Not available

SEO Keywords: SEO keywords not available


20. Each time your test invokes onView(), Espresso waits to perform the corresponding UI action or assertion until the following synchronization conditions are met: (Choose three.)

Page: Page 5

Option A: The message queue is empty.

Option B: The message queue is not empty.

Option C: There are some instances of AsyncTask currently executing a task.

Option D: There are no instances of AsyncTask currently executing a task.

Answer(s):

Explanation: Not available

SEO Keywords: SEO keywords not available


21. To run your local unit tests, follow these steps: 1. Be sure your project is synchronized with Gradle by clicking Sync Project in the toolbar. 2. Run your test in one of the following ways (select possible): (Choose three.)

Page: Page 6

Option A: To run a single test, open the Project window, and then right-click a test and click Run.

Image for Option A: Option A Image

Option B: To test all methods in a class, right-click a class or method in the test file and click Run.

Image for Option B: Option B Image

Option C: To run all tests in a directory, right-click on the directory and select Run tests.

Image for Option C: Option C Image

Option D: To run all tests in Project, open the Project window, and then right-click a test and click Run.

Image for Option D: Option D Image

Answer(s):

Explanation: Not available

SEO Keywords: SEO keywords not available


22. To create a basic JUnit 4 test class, create a class that contains one or more test methods. A test method begins with the specific annotation and contains the code to exercise and verify a single functionality in the component that you want to test. What is the annotation?

Page: Page 6

Option A: @RunWith

Option B: @LargeTest

Option C: @Rule

Option D: @Test

Answer(s):

Explanation: Not available

SEO Keywords: SEO keywords not available


23. The Testing Pyramid, shown in the Figure, illustrates how your app should include the three categories of tests: small, medium, and large. Medium tests are integration tests that:

Page: Page 6

Option A: validate your app's behavior one class at a time.

Option B: validate either interactions between levels of the stack within a module, or interactions between related modules.

Option C: validate user journeys spanning multiple modules of your app.

Answer(s):

Explanation: Not available

SEO Keywords: SEO keywords not available


24. The Testing Pyramid, shown in the Figure, illustrates how your app should include the three categories of tests: small, medium, and large. Small tests are unit tests that :

Page: Page 6

Option A: validate your app's behavior one class at a time.

Option B: validate either interactions between levels of the stack within a module, or interactions between related modules.

Option C: validate user journeys spanning multiple modules of your app.

Answer(s):

Explanation: Not available

SEO Keywords: SEO keywords not available


25. What is illustrated in the picture?

Page: Page 7

Option A: Logcat window with filter settings

Option B: Debugging native code using LLDB

Option C: The Variables and Watches panes in the Debugger window

Option D: The Breakpoints window lists all the current breakpoints and includes behavior settings for each

Answer(s):

Explanation: Not available

SEO Keywords: SEO keywords not available


26. What is illustrated in the picture?

Page: Page 7

Option A: Logcat window with filter settings

Option B: Debugging native code using LLDB

Option C: The Variables and Watches panes in the Debugger window

Option D: The Breakpoints window lists all the current breakpoints and includes behavior settings for each

Answer(s):

Explanation: Not available

SEO Keywords: SEO keywords not available


27. When your code execution reaches the breakpoint, Android Studio pauses execution of your app. You can then use the tools in the Debugger tab to identify the state of the app. With Step Into you can

Page: Page 7

Option A: examine the object tree for a variable, expand it in the Variables view. If the Variables view is not visible

Option B: evaluate an expression at the current execution point

Option C: advance to the next line in the code (without entering a method)

Option D: advance to the first line inside a method call

Answer(s):

Explanation: Not available

SEO Keywords: SEO keywords not available


28. When your code execution reaches the breakpoint, Android Studio pauses execution of your app. You can then use the tools in the Debugger tab to identify the state of the app. With Evaluate Expression you can

Page: Page 7

Option A: examine the object tree for a variable; expand it in the Variables view

Option B: evaluate an expression at the current execution point

Option C: advance to the next line in the code (without entering a method)

Option D: advance to the first line inside a method call

Answer(s):

Explanation: Not available

SEO Keywords: SEO keywords not available


29. When your code execution reaches the breakpoint, Android Studio pauses execution of your app. You can then use the tools in the Debugger tab to identify the state of the app. With Step Over you can

Page: Page 8

Option A: examine the object tree for a variable; expand it in the Variables view.

Option B: evaluate an expression at the current execution point

Option C: advance to the next line in the code (without entering a method)

Option D: advance to the first line inside a method call

Answer(s):

Explanation: Not available

SEO Keywords: SEO keywords not available


30. When your code execution reaches the breakpoint, Android Studio pauses execution of your app. You can then use the tools in the Debugger tab to identify the state of the app. With Step Out you can

Page: Page 8

Option A: examine the object tree for a variable; expand it in the Variables view. If the Variables view is not visible

Option B: evaluate an expression at the current execution point

Option C: advance to the next line in the code (without entering a method)

Option D: advance to the first line inside a method call

Answer(s):

Explanation: Not available

SEO Keywords: SEO keywords not available


Top Post Ad

Post a Comment