You are on page 1of 13

Chap 7:

What is an Activity in Android?


A. A type of service that runs in the background.
B. A visual user interface focused on a single thing a user can do.
C. A way to make some of the application data available to other applications.
D. A type of broadcast receiver that reacts to incoming messages.

What is the lifecycle of an Activity in Android?


A. onCreate() -> onPause() -> onResume() -> onDestroy()
B. onCreate() -> onStart() -> onResume() -> onPause() -> onStop() -> onRestart() -> onDestroy()
C. onCreate() -> onStart() -> onResume() -> onPause() -> onStop() -> onDestroy()
D. onCreate() -> onPause() -> onStop() -> onDestroy()

Which method is called when an Activity is first created?


A. onCreate()
B. onPause()
C. onStop()
D. onResume()

Which method is called when an Activity is no longer visible?


A. onCreate()
B. onPause()
C. onStop()
D. onResume()

Which method is called when an Activity is brought back to the foreground?


A. onCreate()
B. onPause()
C. onStop()
D. onResume()

Which method is called when an Activity is destroyed and removed from memory?
A. onCreate()
B. onPause()
C. onStop()
D. onDestroy()

What is the purpose of onSaveInstanceState() method in Android?


A. To save data before the Activity is destroyed.
B. To save data when the Activity is paused.
C. To save data when the Activity is stopped.
D. To save data when the Activity is resumed.

Which method is called when an Activity is re-created after being destroyed and removed from
memory?
A. onCreate()
B. onPause()
C. onStop()
D. onRestart()

What is the purpose of onStart() method in Android?


A. To initialize an Activity before it becomes visible.
B. To start a new Activity.
C. To stop an Activity.
D. To pause an Activity.
Which method is called when an Activity is no longer visible but still partially visible on the screen?
A. onCreate()
B. onPause()
C. onStop()
D. onResume()

Chap 8
What is an Intent in Android?
A. A visual user interface focused on a single thing a user can do.
B. A way to make some of the application data available to other applications.
C. A message object that is used to communicate between components in an application.
D. A type of broadcast receiver that reacts to incoming messages.

What is an explicit Intent in Android?


A. An Intent that is sent to a specific component by specifying its name.
B. An Intent that is sent to any available component that can handle it.
C. An Intent that is sent to broadcast receivers.
D. An Intent that is used to share data between applications.

What is an implicit Intent in Android?


A. An Intent that is sent to a specific component by specifying its name.
B. An Intent that is sent to any available component that can handle it.
C. An Intent that is sent to broadcast receivers.
D. An Intent that is used to share data between applications.

Which method is used to start a new Activity using an Intent in Android?


A. startActivity()
B. startActivityForResult()
C. setResult()
D. finish()

How do you pass data between Activities using an Intent in Android?


A. By calling startActivity() method with the data as parameter.
B. By calling setResult() method with the data as parameter.
C. By using Intent extras to add the data to the Intent before starting the Activity.
D. By calling startActivityForResult() method with the data as parameter.

How do you receive data from a previous Activity in the current Activity in Android?
A. By calling startActivity() method with the data as parameter.
B. By calling setResult() method with the data as parameter.
C. By using Intent extras to add the data to the Intent before starting the Activity.
D. By overriding the onActivityResult() method and extracting the data from the Intent.

How do you start an Activity and receive a result back from it in Android?
A. By calling startActivity() method and passing the data as parameter.
B. By calling setResult() method and passing the data as parameter.
C. By using Intent extras to add the data to the Intent before starting the Activity.
D. By calling startActivityForResult() method and waiting for the result in the onActivityResult()
method.

What is the purpose of the Intent.FLAG_ACTIVITY_CLEAR_TOP flag in Android?


A. To start a new Activity on top of the current Activity.
B. To clear the back stack of Activities up to and including the current Activity.
C. To clear the back stack of Activities up to the last instance of the specified Activity.
D. To clear the top Activity on the back stack.
What is the purpose of the Intent.FLAG_ACTIVITY_NEW_TASK flag in Android?
A. To start a new Activity on top of the current Activity.
B. To clear the back stack of Activities up to and including the current Activity.
C. To start a new Activity in a new task stack.
D. To clear the top Activity on the back stack.

What is the purpose of the Intent.ACTION_VIEW action in Android?


A. To start a new Activity to view data in the current application.
B. To start a new Activity to view data in a different application.
C. To start a new Activity to edit data in the current application.
D. To start a new Activity to share data with other applications.

Chap 9
What is a RecyclerView in Android?
A) A layout that arranges views in a grid format
B) A view that displays a list of items in a vertical or horizontal scrollable list
C) A class that manages the lifecycle of an activity or fragment
D) A type of service that runs in the background
Answer: B

What is the difference between RecyclerView and ListView?


A) RecyclerView is a newer and more efficient way to display lists
B) RecyclerView can only display items in a vertical orientation
C) ListView can display items in a grid format
D) ListView is no longer supported by Android
Answer: A

What is an adapter in RecyclerView?


A) A class that creates and manages the layout of views in RecyclerView
B) A class that manages the data for each view in RecyclerView
C) A layout that defines the appearance of each view in RecyclerView
D) A method that initializes the RecyclerView and sets its layout manager
Answer: B

What is a ViewHolder in RecyclerView?


A) A layout that defines the appearance of each view in RecyclerView
B) A class that manages the data for each view in RecyclerView
C) A class that holds references to the views in each item of RecyclerView
D) A method that initializes the RecyclerView and sets its layout manager
Answer: C

What is the purpose of the onCreateViewHolder method in RecyclerView.Adapter?


A) To create a new instance of the RecyclerView
B) To create a new instance of the ViewHolder
C) To inflate the layout for each item in the RecyclerView
D) To bind data to the views in each item of the RecyclerView
Answer: B

What is the purpose of the onBindViewHolder method in RecyclerView.Adapter?


A) To create a new instance of the RecyclerView
B) To create a new instance of the ViewHolder
C) To inflate the layout for each item in the RecyclerView
D) To bind data to the views in each item of the RecyclerView
Answer: D

What is the purpose of the getItemCount method in RecyclerView.Adapter?


A) To create a new instance of the RecyclerView
B) To create a new instance of the ViewHolder
C) To inflate the layout for each item in the RecyclerView
D) To return the number of items in the data set
Answer: D

What is a LayoutManager in RecyclerView?


A) A class that creates and manages the layout of views in RecyclerView
B) A class that manages the data for each view in RecyclerView
C) A layout that defines the appearance of each view in RecyclerView
D) A method that initializes the RecyclerView and sets its layout manager
Answer: A

Which method should you call to add or remove items from a RecyclerView?
A) notifyDataSetChanged()
B) notifyItemChanged()
C) notifyItemInserted() and notifyItemRemoved()
D) notifyItemRangeChanged()
Answer: C

What is the purpose of the DiffUtil class in RecyclerView?


A) To create a new instance of the RecyclerView
B) To create a new instance of the ViewHolder
C) To calculate the difference between two lists of data and update the RecyclerView accordingly
D) To handle click events on items in the RecyclerView
Answer: C

Chap 10:
Which method can be used to load an image into an ImageView in Android?
a) setImageResource()
b) setImageBitmap()
c) setImageDrawable()
d) All of the above

Which of the following is NOT a commonly used image file format in Android?
a) PNG
b) JPEG
c) GIF
d) MP4

What is a menu in Android?


a) A layout file used to display images
b) A group of items that provide actions or options for an app user
c) A component used to display images and videos in a list
d) A type of animation used to transition between activities

Which method can be used to inflate a menu in Android?


a) onCreateOptionsMenu()
b) onPrepareOptionsMenu()
c) onOptionsItemSelected()
d) Both A and B

What is the purpose of the ActionBar in Android?


a) To display a menu for an activity
b) To provide a title and navigation for an activity
c) To display an image in an activity
d) To display a list of items in an activity
Which layout is commonly used to display a list of items in Android?
a) ConstraintLayout
b) LinearLayout
c) RelativeLayout
d) RecyclerView

What is the purpose of an adapter in Android?


a) To define the layout of an activity
b) To connect a RecyclerView to a data source
c) To provide options for an ActionBar menu
d) To define the behavior of a FloatingActionButton

Which of the following is NOT a commonly used type of adapter in Android?


a) RecyclerView.Adapter
b) ArrayAdapter
c) CursorAdapter
d) ActionBarAdapter

Which method is used to handle clicks on items in a RecyclerView in Android?


a) onClickListener()
b) onItemClick()
c) onItemTouchListener()
d) Both A and B

Which of the following is NOT a commonly used type of menu in Android?


a) PopupMenu
b) ContextMenu
c) ActionBarMenu
d) OptionsMenu

Chap 11:
What are Android Permissions used for?
a) To make an app more user-friendly
b) To protect user privacy and security
c) To improve app performance
d) Both B and C
Answer: b) To protect user privacy and security

Which file in an Android app specifies the permissions required by the app?
a) AndroidManifest.xml
b) MainActivity.java
c) build.gradle
d) strings.xml
Answer: a) AndroidManifest.xml

Which of the following is NOT a permission group in Android?


a) CAMERA
b) STORAGE
c) LOCATION
d) INTERNET
Answer: d) INTERNET

How are permissions requested from the user in Android?


a) Automatically granted when the app is installed
b) Requested through a pop-up dialog box
c) Requested through an email
d) None of the above
Answer: b) Requested through a pop-up dialog box

What happens if an app requests a permission that the user has previously denied?
a) The permission is automatically granted without prompting the user again
b) The app cannot perform the action that requires the permission
c) The user is prompted again to grant the permission
d) The app is uninstalled from the device
Answer: c) The user is prompted again to grant the permission

What is the difference between a normal permission and a dangerous permission in Android?
a) There is no difference
b) Normal permissions do not require user approval, while dangerous permissions do
c) Dangerous permissions are only granted to system apps, while normal permissions can be granted
to any app
d) Dangerous permissions are only used for system-level operations, while normal permissions are
used for app-level operations
Answer: b) Normal permissions do not require user approval, while dangerous permissions do

What is the recommended approach for handling permission requests in Android?


a) Automatically grant all permissions requested by the app
b) Always deny permission requests from the app
c) Only grant permissions that are absolutely necessary for the app to function
d) None of the above
Answer: c) Only grant permissions that are absolutely necessary for the app to function

Which of the following is NOT a best practice for handling Android permissions?
a) Explain to the user why the permission is necessary
b) Request all permissions at once to avoid multiple prompts
c) Handle permission requests in a graceful and user-friendly way
d) Respect the user's decision if they deny a permission request
Answer: b) Request all permissions at once to avoid multiple prompts

Chap 12:
What is an Android notification?
a) A pop-up message that appears on the device's lock screen
b) A message that appears in the device's notification shade
c) A message that appears in the app's main interface
d) Both A and B
Answer: d) Both A and B

What is a Notification Channel in Android?


a) A way to group similar notifications together
b) A way to customize the appearance and behavior of notifications
c) A way to schedule notifications to appear at specific times
d) A way to track user engagement with notifications
Answer: a) A way to group similar notifications together

How do you create a Notification Channel in Android?


a) Through the device's settings menu
b) Through the app's code
c) Through the Google Play Console
d) None of the above
Answer: b) Through the app's code

What is the purpose of a PendingIntent in Android notifications?


a) To launch the app when the notification is clicked
b) To dismiss the notification when it is clicked
c) To play a sound when the notification is clicked
d) To send a message to the user when the notification is clicked
Answer: a) To launch the app when the notification is clicked

How can you add an action button to an Android notification?


a) By including HTML code in the notification text
b) By adding an Intent to the notification
c) By specifying a RemoteViews layout for the notification
d) By using the NotificationCompat.Builder.addAction() method
Answer: d) By using the NotificationCompat.Builder.addAction() method

What is the purpose of a Big Picture Style notification in Android?


a) To show a large image in the notification
b) To show multiple images in the notification
c) To provide more detailed information in the notification
d) To customize the appearance of the notification
Answer: a) To show a large image in the notification

Which of the following is NOT a type of Android notification?


a) Heads-up notification
b) Toast notification
c) In-app notification
d) Silent notification
Answer: c) In-app notification

How can you handle user interactions with Android notifications?


a) By using the NotificationCompat.Builder.setContentIntent() method
b) By creating a custom view for the notification
c) By using the NotificationCompat.Builder.setCustomActions() method
d) Both A and C
Answer: d) Both A and C

Chap 13:
What is the purpose of shared preferences in Android?
A) To store small amounts of data as key-value pairs
B) To store large amounts of structured data in a SQLite database
C) To store files and directories in internal or external storage
D) To store data in a cloud-based service
Answer: A) To store small amounts of data as key-value pairs

Which method can be used to read from a file in internal storage in Android?
A) openFileOutput()
B) openFileInput()
C) getExternalFilesDir()
D) getFilesDir()
Answer: B) openFileInput()

Which type of storage can be used to store large files in Android?


A) Internal storage
B) External storage
C) SQLite database
D) SharedPreferences
Answer: B) External storage

Which method can be used to delete a file from internal storage in Android?
A) deleteFile()
B) getFilesDir()
C) openFileInput()
D) openFileOutput()
Answer: A) deleteFile()

Which storage option is recommended for sensitive data in Android?


A) Internal storage
B) External storage
C) SQLite database
D) SharedPreferences
Answer: A) Internal storage

Which type of storage can be accessed by other apps in Android?


A) Internal storage
B) External storage
C) SQLite database
D) SharedPreferences
Answer: B) External storage

Which method can be used to write to a file in internal storage in Android?


A) openFileOutput()
B) openFileInput()
C) getExternalFilesDir()
D) getFilesDir()
Answer: A) openFileOutput()

Which method can be used to check if external storage is available in Android?


A) getExternalStorageState()
B) getFilesDir()
C) openFileInput()
D) openFileOutput()
Answer: A) getExternalStorageState()

Which storage option is recommended for caching data in Android?


A) Internal storage
B) External storage
C) SQLite database
D) SharedPreferences
Answer: A) Internal storage

Which method can be used to write to a file in external storage in Android?


A) openFileOutput()
B) openFileInput()
C) getExternalFilesDir()
D) getFilesDir()
Answer: A) openFileOutput()

Chap 14
What is a content provider in Android?
A) A mechanism for managing application resources
B) A component that allows data sharing between applications
C) A layout container for organizing user interface elements
D) A service that runs in the background indefinitely
Answer: B) A component that allows data sharing between applications

Which method is used to query a content provider in Android?


A) getContentResolver()
B) query()
C) insert()
D) update()
Answer: B) query()

Which permission is required to access a content provider in Android?


A) READ_CONTACTS
B) WRITE_EXTERNAL_STORAGE
C) ACCESS_FINE_LOCATION
D) INTERNET
Answer: A) READ_CONTACTS

Which method is used to insert data into a content provider in Android?


A) getContentResolver()
B) query()
C) insert()
D) update()
Answer: C) insert()

Which method is used to update data in a content provider in Android?


A) getContentResolver()
B) query()
C) insert()
D) update()
Answer: D) update()

Which content provider is used to store and retrieve system settings in Android?
A) ContactsContract
B) Settings.System
C) MediaStore
D) CallLog.Calls
Answer: B) Settings.System

Which content provider is used to store and retrieve media files in Android?
A) ContactsContract
B) Settings.System
C) MediaStore
D) CallLog.Calls
Answer: C) MediaStore

Which method is used to delete data from a content provider in Android?


A) getContentResolver()
B) query()
C) insert()
D) delete()
Answer: D) delete()

Which content provider is used to store and retrieve contact information in Android?
A) ContactsContract
B) Settings.System
C) MediaStore
D) CallLog.Calls
Answer: A) ContactsContract

Which method is used to get the URI of a content provider in Android?


A) getContentResolver()
B) getUri()
C) getContentUri()
D) query()
Answer: C) getContentUri()
Chap 15
What is an Android service?
A) A visual user interface for a single task
B) A component that runs in the background indefinitely
C) A mechanism for data exchange between applications
D) A layout container for organizing user interface elements
Answer: B) A component that runs in the background indefinitely

Which method is used to start a service in Android?


A) startService()
B) bindService()
C) onCreate()
D) onStartCommand()
Answer: A) startService()

Which method is used to stop a service in Android?


A) stopService()
B) unbindService()
C) onDestroy()
D) onStop()
Answer: A) stopService()

Which method is used to communicate with a service in Android?


A) sendBroadcast()
B) startService()
C) bindService()
D) onStartCommand()
Answer: C) bindService()

Which type of service does not create a separate process?


A) Foreground service
B) Background service
C) Started service
D) Bound service
Answer: D) Bound service

Which type of service displays a persistent notification to the user?


A) Foreground service
B) Background service
C) Started service
D) Bound service
Answer: A) Foreground service

Which method is used to check if a service is running in Android?


A) isServiceRunning()
B) checkService()
C) startService()
D) bindService()
Answer: A) isServiceRunning()

Which method is used to schedule a task to be executed repeatedly in the background?


A) Handler.postDelayed()
B) AlarmManager.setRepeating()
C) Timer.schedule()
D) AsyncTask.execute()
Answer: B) AlarmManager.setRepeating()

Which method is used to create a new thread to perform background tasks?


A) AsyncTask.execute()
B) Service.onStartCommand()
C) Handler.postDelayed()
D) Activity.onCreate()
Answer: A) AsyncTask.execute()

Which permission is required to start a service in Android?


A) READ_EXTERNAL_STORAGE
B) ACCESS_FINE_LOCATION
C) INTERNET
D) None
Answer: D) None (Starting a service does not require any permission)

Chap 16
What is multithreading?
A. Running multiple instances of an app on a device
B. Running multiple tasks simultaneously within an app
C. Running an app in the background
D. Running an app on multiple devices simultaneously
Answer: B

Which of the following is an advantage of using multithreading in an Android app?


A. It makes the app run faster
B. It allows the app to use more memory
C. It allows the app to handle multiple tasks simultaneously
D. It makes the app more visually appealing
Answer: C

Which of the following is NOT true about the main (UI) thread in Android?
A. It handles all user interface interactions
B. It should be used for long-running tasks
C. It can be blocked by long-running tasks, causing the app to become unresponsive
D. It should only be used for short, lightweight tasks
Answer: B

What is the purpose of the AsyncTask class in Android?


A. To perform long-running tasks in the main thread
B. To perform short, lightweight tasks in a background thread
C. To create new threads in an Android app
D. To communicate between threads in an Android app
Answer: B

Which of the following is a correct way to start a new thread in an Android app?
A. Create a new instance of the Thread class and call its start() method
B. Call the run() method on the current thread
C. Create a new instance of the Runnable interface and call its start() method
D. Create a new instance of the Thread class and call its run() method
Answer: A

Which of the following methods is used to update the UI from a background thread in Android?
A. runOnUiThread()
B. post()
C. sendBroadcast()
D. start()
Answer: A

What is a Handler in Android?


A. A class used to create new threads
B. A class used to manage communication between threads
C. A class used to update the UI from a background thread
D. A class used to perform long-running tasks in a background thread
Answer: B

Which of the following is NOT a type of thread pool executor in Android?


A. FixedThreadPool
B. CachedThreadPool
C. ScheduledThreadPool
D. OrderedThreadPool
Answer: D

What is the purpose of the Looper class in Android?


A. To manage threads in an Android app
B. To perform long-running tasks in a background thread
C. To update the UI from a background thread
D. To loop through a message queue in a thread
Answer: D

What is a race condition in multithreading?


A. When two or more threads try to modify the same data at the same time
B. When two or more threads try to access different data at the same time
C. When a thread is blocked by another thread
D. When a thread is running for too long and causing the app to become unresponsive
Answer: A

Chap 17
What is a Fragment in Android?
A. A part of an activity that can be reused in different activities.
B. A separate standalone activity in Android.
C. A component used to communicate with other applications.
D. A widget used for displaying images and text.
Answer: A. A part of an activity that can be reused in different activities.

What is the purpose of using Fragments in Android?


A. To reduce memory consumption and improve performance.
B. To provide a visual user interface for a single task.
C. To handle data exchange between applications.
D. To store and retrieve data.
Answer: A. To reduce memory consumption and improve performance.

Which method is used to add a Fragment to an Activity?


A. addFragment()
B. attachFragment()
C. insertFragment()
D. replace()
Answer: D. replace()

What is the difference between a Fragment and an Activity in Android?


A. An Activity can contain multiple Fragments, but a Fragment cannot contain an Activity.
B. A Fragment can be reused in different Activities, but an Activity cannot be reused.
C. A Fragment has its own lifecycle, while an Activity has a separate lifecycle.
D. A Fragment can exist without an Activity, but an Activity cannot exist without a Fragment.
Answer: C. A Fragment has its own lifecycle, while an Activity has a separate lifecycle.

How can you communicate between Fragments in Android?


A. Using an Intent.
B. Using a BroadcastReceiver.
C. Using a Content Provider.
D. Using a Callback interface.
Answer: D. Using a Callback interface.

Which method is called to inflate the layout of a Fragment?


A. onCreateView()
B. onCreate()
C. onStart()
D. onResume()
Answer: A. onCreateView()

Which of the following is not a Fragment lifecycle method in Android?


A. onAttach()
B. onDetach()
C. onLayout()
D. onDestroy()
Answer: C. onLayout()

What is the purpose of the FragmentManager in Android?


A. To manage the lifecycle of Fragments.
B. To handle communication between Fragments.
C. To manage the back stack of Fragments.
D. To handle the navigation between Activities.
Answer: C. To manage the back stack of Fragments.

Which method is used to add a Fragment to the back stack in Android?


A. addBackStack()
B. addToBackStack()
C. pushBackStack()
D. popBackStack()
Answer: B. addToBackStack()

Which layout is commonly used for Fragments in Android?


A. LinearLayout
B. RelativeLayout
C. FrameLayout
D. GridLayout
Answer: C. FrameLayout

You might also like