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? Service Content Provider Fragment 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? ScaleGestureDetector TouchDelegate GestureDetector MotionLayout Answer: C) GestureDetector
Explanation: GestureDetector recognises common gestures.
Discuss this question
3. Which data type can NOT be stored directly in SharedPreferences? A Bitmap image Set of Strings Float 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? onCreateViewHolder() getItemCount() onBindViewHolder() onAttachedToRecyclerView() Answer: A) onCreateViewHolder()
Explanation: onCreateViewHolder creates the ViewHolder with an inflated row.
Discuss this question
5. Scoped storage (Android 10/11+) means apps: Cannot save any files Have free access to their own folders but use MediaStore/SAF for shared files Can read every file on the SD card 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: OnKeyListener TextWatcher OnCheckedChangeListener OnFocusChangeListener Answer: C) OnCheckedChangeListener
Explanation: CompoundButton.OnCheckedChangeListener reports state changes.
Discuss this question
7. Which class helps create and upgrade an SQLite database? SQLiteOpenHelper ContentResolver CursorAdapter SharedPreferences Answer: A) SQLiteOpenHelper
Explanation: SQLiteOpenHelper provides onCreate and onUpgrade.
Discuss this question
8. In Room, a class annotated with @Entity represents a: Database connection Table Query Activity Answer: B) Table
Explanation: Each entity becomes a table.
Discuss this question
9. To display items in a two-column grid, use: ScrollView LinearLayoutManager GridLayoutManager(context, 2) 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? inflate() onBindViewHolder() notifyAll() 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? prefs.getString("username", "Guest") prefs.read("username") prefs.username 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: DialogFragment only NotificationCompat PreferenceFragmentCompat RecyclerView only Answer: C) PreferenceFragmentCompat
Explanation: The AndroidX Preference library uses PreferenceFragmentCompat.
Discuss this question
13. A content URI begins with: file:// content:// data:// 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: Is recommended Throws an exception, because database work must be off the main thread Is faster 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: PackageInstaller LayoutInflater FragmentManager 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: Manifest Layout DAO (Data Access Object) interface ViewModel Answer: C) DAO (Data Access Object) interface
Explanation: DAOs contain annotated query methods.
Discuss this question
17. DiffUtil with ListAdapter helps by: Saving to SQLite Updating only the rows that changed Translating text 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: The long press repeats The click is ignored The app closes 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? OnClickListener only OnCheckedChangeListener OnItemSelectedListener OnEditorActionListener Answer: C) OnItemSelectedListener
Explanation: AdapterView.OnItemSelectedListener reports the chosen item.
Discuss this question
20. SharedPreferences data is removed when: The app is uninstalled or its data is cleared The activity rotates The app goes to the background 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: A file:// URI SharedPreferences FileProvider with a temporary content:// URI 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: JSON documents in the cloud Tables with rows Key–value pairs 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? OnClickListener OnFocusChangeListener TextWatcher OnSeekBarChangeListener Answer: A) OnClickListener
Explanation: OnClickListener's onClick is called on a tap.
Discuss this question
24. Which widget shows a star rating? RatingBar SeekBar Chip 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? ACTIONDOWN ACTIONMOVE ACTIONUP 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