MCQs / Computer Science / UI Events, Views, Preferences and Data Storage

UI Events, Views, Preferences and Data Storage MCQs — Computer Science

39 multiple-choice questions on UI Events, Views, Preferences and Data Storage 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 Android component lets an app share structured data with other apps?

  1. Service
  2. Content Provider
  3. Fragment
  4. BroadcastReceiver

Answer: B) Content Provider

Explanation: Content providers expose data through content URIs.

Discuss this question

2. Which class detects fling and double-tap gestures?

  1. ScaleGestureDetector
  2. TouchDelegate
  3. GestureDetector
  4. MotionLayout

Answer: C) GestureDetector

Explanation: GestureDetector recognises common gestures.

Discuss this question

3. Which data type can NOT be stored directly in SharedPreferences?

  1. A Bitmap image
  2. Set of Strings
  3. Float
  4. Boolean

Answer: A) A Bitmap image

Explanation: Only primitives, Strings and String sets are supported.

Discuss this question

4. Which RecyclerView adapter method inflates a row layout?

  1. onCreateViewHolder()
  2. getItemCount()
  3. onBindViewHolder()
  4. onAttachedToRecyclerView()

Answer: A) onCreateViewHolder()

Explanation: onCreateViewHolder creates the ViewHolder with an inflated row.

Discuss this question

5. Scoped storage (Android 10/11+) means apps:

  1. Cannot save any files
  2. Have free access to their own folders but use MediaStore/SAF for shared files
  3. Can read every file on the SD card
  4. Need root access

Answer: B) Have free access to their own folders but use MediaStore/SAF for shared files

Explanation: Scoped storage limits broad file access.

Discuss this question

6. The listener notified when a CheckBox is ticked or unticked is:

  1. OnKeyListener
  2. TextWatcher
  3. OnCheckedChangeListener
  4. OnFocusChangeListener

Answer: C) OnCheckedChangeListener

Explanation: CompoundButton.OnCheckedChangeListener reports state changes.

Discuss this question

7. Which class helps create and upgrade an SQLite database?

  1. SQLiteOpenHelper
  2. ContentResolver
  3. CursorAdapter
  4. SharedPreferences

Answer: A) SQLiteOpenHelper

Explanation: SQLiteOpenHelper provides onCreate and onUpgrade.

Discuss this question

8. In Room, a class annotated with @Entity represents a:

  1. Database connection
  2. Table
  3. Query
  4. Activity

Answer: B) Table

Explanation: Each entity becomes a table.

Discuss this question

9. To display items in a two-column grid, use:

  1. ScrollView
  2. LinearLayoutManager
  3. GridLayoutManager(context, 2)
  4. FrameLayout

Answer: C) GridLayoutManager(context, 2)

Explanation: GridLayoutManager arranges rows in a grid with a given span count.

Discuss this question

10. Which method fills a row with data for a given position?

  1. inflate()
  2. onBindViewHolder()
  3. notifyAll()
  4. onCreateViewHolder()

Answer: B) onBindViewHolder()

Explanation: onBindViewHolder binds data to the row views.

Discuss this question

11. Which is the correct way to read a string preference with a default value?

  1. prefs.getString("username", "Guest")
  2. prefs.read("username")
  3. prefs.username
  4. prefs.getString("username")

Answer: A) prefs.getString("username", "Guest")

Explanation: The second parameter is returned if the key is missing.

Discuss this question

12. Settings screens built from XML preferences are displayed with:

  1. DialogFragment only
  2. NotificationCompat
  3. PreferenceFragmentCompat
  4. RecyclerView only

Answer: C) PreferenceFragmentCompat

Explanation: The AndroidX Preference library uses PreferenceFragmentCompat.

Discuss this question

13. A content URI begins with:

  1. file://
  2. content://
  3. data://
  4. http://

Answer: B) content://

Explanation: Content providers use the content:// scheme.

Discuss this question

14. Running a Room query on the main (UI) thread by default:

  1. Is recommended
  2. Throws an exception, because database work must be off the main thread
  3. Is faster
  4. Deletes the table

Answer: B) Throws an exception, because database work must be off the main thread

Explanation: Room blocks main-thread access to keep the UI responsive.

Discuss this question

15. Apps access a content provider through a:

  1. PackageInstaller
  2. LayoutInflater
  3. FragmentManager
  4. ContentResolver

Answer: D) ContentResolver

Explanation: ContentResolver sends query/insert/update/delete calls to providers.

Discuss this question

16. Room methods that read or write the database are declared in a:

  1. Manifest
  2. Layout
  3. DAO (Data Access Object) interface
  4. ViewModel

Answer: C) DAO (Data Access Object) interface

Explanation: DAOs contain annotated query methods.

Discuss this question

17. DiffUtil with ListAdapter helps by:

  1. Saving to SQLite
  2. Updating only the rows that changed
  3. Translating text
  4. Encrypting data

Answer: B) Updating only the rows that changed

Explanation: DiffUtil computes the difference between old and new lists.

Discuss this question

18. Returning true from onLongClick() means:

  1. The long press repeats
  2. The click is ignored
  3. The app closes
  4. The event is consumed and no further click is triggered

Answer: D) The event is consumed and no further click is triggered

Explanation: true consumes the event.

Discuss this question

19. Which listener is used with a Spinner?

  1. OnClickListener only
  2. OnCheckedChangeListener
  3. OnItemSelectedListener
  4. OnEditorActionListener

Answer: C) OnItemSelectedListener

Explanation: AdapterView.OnItemSelectedListener reports the chosen item.

Discuss this question

20. SharedPreferences data is removed when:

  1. The app is uninstalled or its data is cleared
  2. The activity rotates
  3. The app goes to the background
  4. The phone restarts

Answer: A) The app is uninstalled or its data is cleared

Explanation: Preferences persist across restarts until uninstall or clear data.

Discuss this question

21. To share a private file (e.g. a PDF) with another app securely, use:

  1. A file:// URI
  2. SharedPreferences
  3. FileProvider with a temporary content:// URI
  4. A public static variable

Answer: C) FileProvider with a temporary content:// URI

Explanation: FileProvider grants temporary read access; file:// URIs are blocked since Android 7.

Discuss this question

22. SharedPreferences store data as:

  1. JSON documents in the cloud
  2. Tables with rows
  3. Key–value pairs
  4. Images

Answer: C) Key–value pairs

Explanation: SharedPreferences hold simple key–value data.

Discuss this question

23. Which listener responds when a button is tapped?

  1. OnClickListener
  2. OnFocusChangeListener
  3. TextWatcher
  4. OnSeekBarChangeListener

Answer: A) OnClickListener

Explanation: OnClickListener's onClick is called on a tap.

Discuss this question

24. Which widget shows a star rating?

  1. RatingBar
  2. SeekBar
  3. Chip
  4. Switch

Answer: A) RatingBar

Explanation: RatingBar shows and selects star ratings.

Discuss this question

25. Which MotionEvent action is reported when the finger is lifted?

  1. ACTIONDOWN
  2. ACTIONMOVE
  3. ACTIONUP
  4. ACTIONHOVER

Answer: C) ACTIONUP

Explanation: ACTIONUP is sent when the touch ends.

Discuss this question

Page 1 of 2 Next

Practise UI Events, Views, Preferences and Data Storage MCQs

More Computer Science chapters