MCQs / Computer Science / Threading and Publishing Android Applications

Threading and Publishing Android Applications MCQs — Computer Science

34 multiple-choice questions on Threading and Publishing Android Applications from Computer Science, each with the correct answer and, where available, a teacher's explanation. Read through them to revise the chapter, then practise the same questions one by one to test yourself.

1. Which type is used to expose a continuously updated value from a ViewModel to the UI?

  1. Intent
  2. Bundle
  3. StateFlow (or LiveData)
  4. Cursor

Answer: C) StateFlow (or LiveData)

Explanation: StateFlow holds the latest state and emits updates.

Discuss this question

2. AsyncTask was deprecated in:

  1. Android 14
  2. Android 8.0
  3. Android 11 (API 30)
  4. Android 5.0

Answer: C) Android 11 (API 30)

Explanation: AsyncTask is deprecated from API 30; use coroutines or executors.

Discuss this question

3. Updating a TextView from a background thread causes:

  1. OutOfMemoryError
  2. NetworkOnMainThreadException
  3. CalledFromWrongThreadException
  4. ActivityNotFoundException

Answer: C) CalledFromWrongThreadException

Explanation: Only the UI thread may touch views.

Discuss this question

4. "Structured concurrency" means:

  1. Threads are created manually
  2. All coroutines run in a fixed order
  3. Coroutines can only run once
  4. Coroutines are children of a scope, so cancelling the scope cancels them all

Answer: D) Coroutines are children of a scope, so cancelling the scope cancels them all

Explanation: It prevents leaked coroutines.

Discuss this question

5. Which class is deprecated and replaced by WorkManager or JobIntentService alternatives?

  1. IntentService
  2. Activity
  3. Service
  4. Fragment

Answer: A) IntentService

Explanation: IntentService is deprecated from API 30.

Discuss this question

6. Which method runs code on the UI thread from a background thread inside an activity?

  1. runInBackground
  2. Thread.sleep()
  3. runOnUiThread
  4. startService()

Answer: C) runOnUiThread

Explanation: runOnUiThread posts the block to the main thread.

Discuss this question

7. Which dispatcher is best for CPU-intensive work like sorting a huge list?

  1. Dispatchers.Default
  2. Dispatchers.IO
  3. Dispatchers.Main
  4. Dispatchers.UI

Answer: A) Dispatchers.Default

Explanation: Default uses a pool sized to CPU cores.

Discuss this question

8. Coroutines started in viewModelScope are cancelled when:

  1. The user scrolls
  2. The screen rotates
  3. The phone sleeps
  4. The ViewModel is cleared

Answer: D) The ViewModel is cleared

Explanation: viewModelScope survives rotation and is cancelled in onCleared.

Discuss this question

9. Which is NOT a task to move off the main thread?

  1. Setting a TextView's text to a short string
  2. Decoding a large image
  3. Downloading a file
  4. Querying a large database

Answer: A) Setting a TextView's text to a short string

Explanation: Short UI updates belong on the main thread.

Discuss this question

10. Music playback that continues with an ongoing notification should use a:

  1. Toast
  2. WorkManager job
  3. BroadcastReceiver
  4. Foreground service

Answer: D) Foreground service

Explanation: Foreground services perform user-noticeable ongoing work.

Discuss this question

11. With Play App Signing, Google holds the:

  1. Debug keystore
  2. Source code
  3. App signing key, while the developer uses an upload key
  4. Developer's password

Answer: C) App signing key, while the developer uses an upload key

Explanation: Google re-signs delivered APKs with the app signing key.

Discuss this question

12. The file that stores your release signing key is called a:

  1. Keystore (.jks)
  2. Gradle wrapper
  3. Bundle
  4. Manifest

Answer: A) Keystore (.jks)

Explanation: The keystore holds the private key and certificate.

Discuss this question

13. R8 in release builds is used to:

  1. Sign the APK
  2. Create the keystore
  3. Shrink, optimise and obfuscate code and remove unused resources
  4. Upload to Play

Answer: C) Shrink, optimise and obfuscate code and remove unused resources

Explanation: R8 replaces ProGuard for shrinking and obfuscation.

Discuss this question

14. The applicationId of a published app:

  1. Can be changed with every update
  2. Is the app's display name
  3. Must stay the same forever; changing it creates a different app
  4. Is optional

Answer: C) Must stay the same forever; changing it creates a different app

Explanation: Play identifies apps by their application ID.

Discuss this question

15. A coroutine is best described as:

  1. A layout
  2. A lightweight, suspendable computation that does not block threads
  3. A database table
  4. A heavy operating-system thread

Answer: B) A lightweight, suspendable computation that does not block threads

Explanation: Coroutines suspend instead of blocking, so many can run on few threads.

Discuss this question

16. WorkManager constraints can require that work runs only when:

  1. The device has a network connection or is charging
  2. The app is in landscape
  3. The screen is rotated
  4. A Toast is shown

Answer: A) The device has a network connection or is charging

Explanation: Constraints include network type, charging, battery not low, storage not low.

Discuss this question

17. Which value must increase with every new version uploaded to Google Play?

  1. versionName
  2. applicationId
  3. versionCode
  4. minSdk

Answer: C) versionCode

Explanation: versionCode is an integer compared by Play to identify newer builds.

Discuss this question

18. An ANR dialog appears when the main thread does not respond to input for about:

  1. 1 second
  2. 2 minutes
  3. 5 seconds
  4. 30 seconds

Answer: C) 5 seconds

Explanation: Input dispatch timeout is about 5 seconds.

Discuss this question

19. Which Jetpack library is recommended for deferrable work that must run even after the app closes or the device restarts?

  1. WorkManager
  2. Navigation
  3. Room
  4. AppCompat

Answer: A) WorkManager

Explanation: WorkManager guarantees execution under constraints.

Discuss this question

20. Two threads waiting for each other forever is called:

  1. ANR
  2. Fragmentation
  3. Race condition
  4. Deadlock

Answer: D) Deadlock

Explanation: Deadlock blocks both threads permanently.

Discuss this question

21. The minimum interval of a periodic WorkManager request is:

  1. 1 hour
  2. 15 minutes
  3. 1 minute
  4. 1 day

Answer: B) 15 minutes

Explanation: PeriodicWorkRequest has a 15-minute minimum.

Discuss this question

22. A Looper's job is to:

  1. Compile code
  2. Run a loop that takes messages from the MessageQueue and dispatches them
  3. Connect to Wi-Fi
  4. Loop animations

Answer: B) Run a loop that takes messages from the MessageQueue and dispatches them

Explanation: Each Looper processes its thread's message queue.

Discuss this question

23. New apps on Google Play must be published as:

  1. ZIP files
  2. Android App Bundles (AAB)
  3. APK files only
  4. IPA files

Answer: B) Android App Bundles (AAB)

Explanation: AAB is mandatory for new apps since August 2021.

Discuss this question

24. Which builder returns a result that can be awaited?

  1. post
  2. launch
  3. runOnUiThread
  4. async

Answer: D) async

Explanation: async returns a Deferred whose result is obtained with await().

Discuss this question

25. A Handler is used to:

  1. Store preferences
  2. Post messages or runnables to a thread's message queue (e.g. delayed tasks)
  3. Draw layouts
  4. Sign APKs

Answer: B) Post messages or runnables to a thread's message queue (e.g. delayed tasks)

Explanation: Handlers work with Loopers and MessageQueues.

Discuss this question

Page 1 of 2 Next

Practise Threading and Publishing Android Applications MCQs

More Computer Science chapters