0% found this document useful (0 votes)
3 views

Basic components of an Android application

The document outlines the basic components and lifecycle methods of Android applications, detailing key elements such as XML files, Activities, Services, BroadcastReceivers, and ContentProviders. It explains the purpose of various directories like 'drawable', 'layout', and 'values', as well as lifecycle methods like onCreate(), onStart(), onResume(), onPause(), onStop(), and onDestroy(). The information serves as a foundational guide for understanding Android application structure and behavior.

Uploaded by

zechariha2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Basic components of an Android application

The document outlines the basic components and lifecycle methods of Android applications, detailing key elements such as XML files, Activities, Services, BroadcastReceivers, and ContentProviders. It explains the purpose of various directories like 'drawable', 'layout', and 'values', as well as lifecycle methods like onCreate(), onStart(), onResume(), onPause(), onStop(), and onDestroy(). The information serves as a foundational guide for understanding Android application structure and behavior.

Uploaded by

zechariha2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 55

Basic components of an Android application

1. What is the primary XML file used to configure the presentation layer of an Android
application?

a) manifest.xml

b) layout.xml

c) strings.xml

d) activity_main.xml

Answer: b) layout.xml

Explanation: The layout XML file is used to define the UI (User Interface) components and
their arrangement within an Android application.

2. Which component is responsible for managing the application's lifecycle and handling user
interactions?

a) Activity

b) Service

c) BroadcastReceiver

d) ContentProvider

Answer: a) Activity

Explanation: Activities represent the presentation layer of an Android application and are
responsible for managing the user interface and handling user interactions.

3. What is the purpose of the AndroidManifest.xml file?

a) To define the layout of the application's user interface

b) To declare the permissions required by the application

c) To specify the resources used in the application

d) To store the application's data persistently

Answer: b) To declare the permissions required by the application

Explanation: The AndroidManifest.xml file contains essential information about the


application, including its permissions, components, and metadata.
4. Which of the following is NOT a valid Android application component?

a) Fragment

b) Intent

c) View

d) Service

Answer: c) View

Explanation: Views are not standalone components in Android applications but are rather UI
elements that are part of the presentation layer, typically defined in layout XML files.

5. Which component is used to perform long-running operations in the background without a


user interface?

a) Activity

b) Service

c) BroadcastReceiver

d) ContentProvider

Answer: b) Service

Explanation: Services are used for tasks that need to run in the background independently of
the application's lifecycle, such as playing music or downloading files.

6. Which component is used to receive and handle system-wide broadcast messages?

a) Activity

b) Service

c) BroadcastReceiver

d) ContentProvider

Answer: c) BroadcastReceiver

Explanation: BroadcastReceivers allow the application to receive and respond to broadcast


messages from other applications or from the system itself.

7. What is the purpose of Intent in Android?

a) To define the layout of the application's user interface


b) To perform asynchronous tasks in the background

c) To declare the permissions required by the application

d) To facilitate communication between components

Answer: d) To facilitate communication between components

Explanation:

Intents are used to trigger activities, services, and broadcast receivers, as well as to pass data
between components within an application or between different applications.

8. Which component is responsible for managing access to a structured set of data?

a) Activity

b) Service

c) BroadcastReceiver

d) ContentProvider

Answer d) ContentProvider

Explanation: ContentProviders manage access to a structured set of data, typically stored in a


SQLite database, and allow data to be shared between different applications.

9. What is the purpose of the "R.java" file in an Android application?

a) To store the application's data persistently

b) To declare the permissions required by the application

c) To dynamically generate unique resource identifiers

d) To define the layout of the application's user interface

Answer: c) To dynamically generate unique resource identifiers

Explanation: The "R.java" file is automatically generated by the Android build tools and
contains unique resource identifiers for all the resources used in the application, such as layouts,
strings, and images.

10. Which method is called when an Activity is first created?

a) onCreate()

b) onStart()
c) onResume()

d) onRestart()

Answer: a) onCreate()

Explanation: The onCreate() method is called when an Activity is first created, and it is
where initialization code, such as UI layout inflation and binding, should be placed.

11. Which component is responsible for managing the lifecycle of an application's data?

a) Activity

b) Service

c) BroadcastReceiver

d) ContentProvider

Answer: d) ContentProvider

Explanation: ContentProviders manage access to structured data, including handling data


storage, retrieval, and modification, and they facilitate data sharing between applications.

12. What is the primary function of the activity_main.xml file in an Android application?

a) To declare the permissions required by the application

b) To define the layout of the application's user interface

c) To specify the resources used in the application

d) To store the application's data persistently

Answer: b) To define the layout of the application's user interface

Explanation The activity_main.xml file contains the layout definitions for the main UI
components of an Activity, specifying their arrangement and appearance.

13. Which method is called when an Activity is no longer visible to the user?

a) onDestroy()

b) onPause()

c) onStop()

d) onDetachedFromWindow()
Answer: c) onStop()

Explanation: The onStop() method is called when an Activity is no longer visible to the
user, either because another Activity has taken over or because the Activity is being destroyed.

14. What is the primary purpose of the setContentView() method in an Activity?

a) To initialize the Activity's state

b) To specify the layout resource to be inflated for the Activity's UI

c) To start another Activity

d) To register the Activity for receiving broadcast messages

Answer: b) To specify the layout resource to be inflated for the Activity's UI

Explanation: The setContentView() method is used to set the layout for the Activity's UI by
specifying the layout resource ID to be inflated.

15. Which component is responsible for handling asynchronous tasks in the background and
updating the UI accordingly?

a) Activity

b) Service

c) AsyncTask

d) BroadcastReceiver

Answer: c) AsyncTask

Explanation: AsyncTask is a utility class provided by Android for performing background


tasks and updating the UI on the main thread with the results.

16. What is the purpose of the "drawable" directory in an Android project?

a) To store layout files for the application

b) To store resources related to the application's user interface

c) To define the permissions required by the application

d) To store application data persistently

Answer: b) To store resources related to the application's user interface


Explanation: The "drawable" directory is used to store drawable resources such as images,
icons, and graphics used in the application's user interface.

17. Which method is called when the user interacts with a menu item in an Activity?

a) onOptionsItemSelected()

b) onCreateOptionsMenu()

c) onPrepareOptionsMenu()

d) onMenuItemSelected()

Answer: a) onOptionsItemSelected()

Explanation: The onOptionsItemSelected() method is called when the user selects a menu
item in the options menu of an Activity, allowing the application to respond to the user's action.

18. What is the purpose of the "res" directory in an Android project?

a) To store source code files

b) To store resources used in the application

c) To define the permissions required by the application

d) To store application data persistently

Answer: b) To store resources used in the application

Explanation: The "res" directory contains various types of resources used in an Android
application, including layouts, drawables, values, and more.

19. Which component is used to display web pages within an Android application?

a) Activity

b) Service

c) WebView

d) BroadcastReceiver

Answer: c) WebView

Explanation: WebView is a view component that allows the display of web pages within an
Android application, enabling the integration of web content into the app's user interface.

20. What is the purpose of the "values" directory in an Android project?


a) To store layout files for the application

b) To store resources related to localization and themes

c) To define the permissions required by the application

d) To store application data persistently

Answer: b) To store resources related to localization and themes

Explanation: The "values" directory is used to store various XML files containing resources
related to localization, themes, styles, and other values used in the application.

21. Which component is responsible for handling touch events and user interactions within an
Android application?

a) Activity

b) View

c) Fragment

d) BroadcastReceiver

Answer: b) View

Explanation: Views are responsible for handling touch events and user interactions within
an Android application, providing the user interface elements with which users interact.

22. What is the purpose of the "drawable-hdpi" directory in an Android project?

a) To store high-density drawable resources

b) To store layout files for high-density screens

c) To define the permissions required by the application

d) To store application data persistently

Answer: a) To store high-density drawable resources

Explanation: The "drawable-hdpi" directory is used to store drawable resources specifically


tailored for high-density screens, ensuring proper rendering on devices with higher pixel
densities.

23. Which method is called when an Activity is brought to the foreground and becomes
interactive?
a) onStart()

b) onResume()

c) onRestart()

d) onRestoreInstanceState()

Answer: b) onResume()

Explanation: The onResume() method is called when an Activity is brought to the


foreground and becomes interactive, allowing the application to resume any paused operations
and update the UI.

24. What is the purpose of the "layout" directory in an Android project?

a) To store resources related to localization and themes

b) To store layout files for the application's user interface

c) To define the permissions required by the application

d) To store application data persistently

Answer: b) To store layout files for the application's user interface

Explanation: The "layout" directory contains XML files that define the layout structure and
appearance of the user interface components within an Android application.

25. Which component is used to display a list of scrollable items in an Android application?

a) RecyclerView

b) ViewPager

c) ListView

d) Spinner

Answer: a) RecyclerView

Explanation: RecyclerView is a flexible and efficient view for displaying a list of scrollable
items, commonly used in Android applications to implement various types of lists and grids.

11. What is the purpose of the "drawable" directory in an Android project?

a) To store layout files for the application

b) To store resources related to the application's user interface


c) To define the permissions required by the application

d) To store application data persistently

Answer: b) To store resources related to the application's user interface

Explanation: The "drawable" directory is used to store drawable resources such as images,
icons, and graphics used in the application's user interface.

12. Which method is called when the user interacts with a menu item in an Activity?

a) onOptionsItemSelected()

b) onCreateOptionsMenu()

c) onPrepareOptionsMenu()

d) onMenuItemSelected()

Answer: a) onOptionsItemSelected()

Explanation: The onOptionsItemSelected() method is called when the user selects a menu
item in the options menu of an Activity, allowing the application to respond to the user's action.

13. What is the purpose of the "res" directory in an Android project?

a) To store source code files

b) To store resources used in the application

c) To define the permissions required by the application

d) To store application data persistently

Answer: b) To store resources used in the application

Explanation: The "res" directory contains various types of resources used in an Android
application, including layouts, drawables, values, and more..

15. What is the purpose of the "drawable-hdpi" directory in an Android project?

a) To store high-density drawable resources

b) To store layout files for high-density screens

c) To define the permissions required by the application

d) To store application data persistently


Answer: a) To store high-density drawable resources

Explanation:The "drawable-hdpi" directory is used to store drawable resources specifically


tailored for high-density screens, ensuring proper rendering on devices with higher pixel

Lifecycle methods of Android application components


1. Which lifecycle method is called when an Activity is first created?

a) onCreate()

b) onStart()

c) onResume()

d) onRestart()

Answer:a) onCreate()

Explanation: The onCreate() method is called when an Activity is first created, and it is where
initialization code, such as setting the content view and binding data, should be placed.

2. Which method is called when an Activity becomes visible to the user?

a) onCreate()

b) onStart()

c) onResume()

d) onPause()

Answer: b) onStart()

Explanation: The onStart() method is called when the Activity becomes visible to the user,
following onCreate() if the Activity is just starting, or onRestart() if it had been stopped.

3. What lifecycle method is called just before the Activity starts interacting with the user?

a) onCreate()

b) onStart()

c) onResume()

d) onPause()

Answer: c) onResume()
Explanation: The onResume() method is called just before the Activity starts interacting
with the user, immediately following onStart().

4. Which lifecycle method is called when the Activity is no longer visible to the user?

a) onPause()

b) onStop()

c) onDestroy()

d) onRestart()

Answer: b) onStop()

Explanation: The onStop() method is called when the Activity is no longer visible to the user,
either because another Activity has taken over or because the Activity is being destroyed.

5. Which method is called when the Activity is partially obscured by another Activity?

a) onPause()

b) onStop()

c) onDestroy() vnnnnn

d) onRestart()

Answer:a) onPause()

Explanation: The onPause() method is called when the Activity is partially obscured by
another Activity, indicating that the user is leaving the Activity.

6. Which lifecycle method is called to restart an Activity that was previously stopped?

a) onCreate()

b) onStart()

c) onResume()

d) onRestart()

Answer: d) onRestart()

Explanation: The onRestart() method is called to restart an Activity that was previously
stopped, usually preceding onStart().

7. What method is called when an Activity is completely shut down and removed from memory?
a) onPause()

b) onStop()

c) onDestroy()

d) onRestart()

Answer: c) onDestroy()

Explanation: The onDestroy() method is called when an Activity is completely shut down
and removed from memory, usually either due to the user finishing the Activity or the system
killing it to save space.

8. In the lifecycle of a Service, which method is called when the Service is first created?

a) onCreate()

b) onStartCommand()

c) onBind()

d) onDestroy()

Answer: a) onCreate()

Explanation: The onCreate() method is called when the Service is first created, allowing for
one-time setup procedures.

9. Which method in the Service lifecycle handles each start request sent to the Service?

a) onCreate()

b) onStartCommand()

c) onBind()

d) onDestroy()

Answer: b) onStartCommand()

Explanation: The onStartCommand() method is called for each start request sent to the
Service, allowing it to handle each request sequentially.

10. Which lifecycle method is called when a Service is no longer in use and is being destroyed?

a) onCreate()

b) onStartCommand()
c) onBind()

d) onDestroy()

Answer: d) onDestroy()

Explanation: The onDestroy() method is called when a Service is no longer in use and is
being destroyed, allowing for cleanup of resources.

11. Which method is called when a Fragment is first attached to its Activity?

a) onCreateView()

b) onAttach()

c) onActivityCreated()

d) onStart()

Answer: b) onAttach()

Explanation: The onAttach() method is called when the Fragment is first attached to its
Activity, allowing the Fragment to reference the Activity before it is created.

12. Which lifecycle method is called to create the view hierarchy of a Fragment?

a) onCreate()

b) onCreateView()

c) onActivityCreated()

d) onStart()

Answer: b) onCreateView()

Explanation: The onCreateView() method is called to create the view hierarchy of the
Fragment, where the layout for the Fragment's UI is inflated and returned.

13. In the lifecycle of a Fragment, which method is called after the Activity’s onCreate() has
completed?

a) onAttach()

b) onCreateView()

c) onActivityCreated()

d) onStart()
Answer: c) onActivityCreated()

Explanation: The onActivityCreated() method is called after the Activity’s onCreate() has
completed, allowing the Fragment to finalize its initialization once the Activity is ready.

14. Which method is called when a Fragment becomes visible to the user?

a) onAttach()

b) onCreate()

c) onStart()

d) onResume()

Answer: c) onStart() Explanation:

The onStart() method is called when a Fragment becomes visible to the user, similar to the
Activity lifecycle.

15. What method is called when a Fragment is visible to the user and actively running?

a) onAttach()

b) onCreate()

c) onStart()

d) onResume()

Answer: d) onResume()

Explanation: The onResume() method is called when a Fragment is visible to the user and
actively running, similar to the Activity lifecycle.

16. Which lifecycle method is called when a Fragment is no longer visible to the user?

a) onPause()

b) onStop()

c) onDestroyView()

d) onDetach()

Answer: b) onStop()

Explanation: The onStop() method is called when a Fragment is no longer visible to the
user, either because it is being replaced or the Activity is being paused or stopped.
17. Which method is called when the view hierarchy associated with a Fragment is being
removed?

a) onPause()

b) onStop()

c) onDestroyView()

d) onDetach()

Answer: c) onDestroyView()

Explanation: The onDestroyView() method is called when the view hierarchy associated
with the Fragment is being removed, allowing for cleanup of resources related to the view.

18. What is the purpose of the onDetach() method in a Fragment’s lifecycle?

a) To create the view hierarchy for the Fragment

b) To handle the Fragment’s visible state

c) To clean up resources when the Fragment is detached from its Activity

d) To finalize initialization once the Activity is created

Answer: c) To clean up resources when the Fragment is detached from its Activity

Explanation: The onDetach() method is called when the Fragment is detached from its
Activity, allowing for cleanup of any remaining resources.

19. Which lifecycle method in a Service is called when a client component calls bindService()?

a) onCreate()

b) onStartCommand()

c) onBind()

d) onDestroy()

Answer: c) onBind()

Explanation: The onBind() method is called when a client component calls bindService(),
allowing the Service to return an IBinder for communication with the client.

20. In the lifecycle of a Service, which method is called to clean up resources before the Service
is destroyed?
a) onCreate()

b) onStartCommand()

c) onBind()

d) onDestroy()

Answer: d) onDestroy()

Explanation: The onDestroy() method is called to clean up resources before the Service is
destroyed, allowing for the release of resources and cleanup of any remaining tasks.

21. Which method is called when a Fragment is first attached to its Activity?

a) onCreateView()

b) onAttach()

c) onActivityCreated()

d) onStart()

Answer: b) onAttach()

Explanation: The onAttach() method is called when the Fragment is first attached to its Activity,
allowing the Fragment to reference the Activity before it is created.

22. Which lifecycle method is called to create the view hierarchy of a Fragment?

a) onCreate()

b) onCreateView()

c) onActivityCreated()

d) onStart()

Answer: b) onCreateView()

Explanation: The onCreateView() method is called to create the view hierarchy of the
Fragment, where the layout for the Fragment's UI is inflated and returned.

23. In the lifecycle of a Fragment, which method is called after the Activity’s onCreate() has
completed?

a) onAttach()

b) onCreateView()
c) onActivityCreated()

d) onStart()

Answer: c) onActivityCreated()

Explanation: The onActivityCreated() method is called after the Activity’s onCreate() has
completed, allowing the Fragment to finalize its initialization once the Activity is ready.

24. Which method is called when a Fragment becomes visible to the user?

a) onAttach()

b) onCreate()

c) onStart()

d) onResume()

Answer: c) onStart()

Explanation: The onStart() method is called when a Fragment becomes visible to the user,
similar to the Activity lifecycle.

25. What method is called when a Fragment is visible to the user and actively running?

a) onAttach()

b) onCreate()

c) onStart()

d) onResume()

Answer: d) onResume()

Explanation: The onResume() method is called when a Fragment is visible to the user and
actively running, similar to the Activity lifecycle

26. Which lifecycle method is called when a Fragment is no longer visible to the user?

a) onPause()

b) onStop()

c) onDestroyView()

d) onDetach()
Answer: b) onStop()

Explanation: The onStop() method is called when a Fragment is no longer visible to the user,
either because it is being replaced or the Activity is being paused or stopped

27. Which method is called when the view hierarchy associated with a Fragment is being
removed?

a) onPause()

b) onStop()

c) onDestroyView()

d) onDetach()

Answer: c) onDestroyView()

Explanation: The onDestroyView() method is called when the view hierarchy associated with
the Fragment is being removed, allowing for cleanup of resources related to the view.

28. What is the purpose of the onDetach() method in a Fragment’s lifecycle?

a) To create the view hierarchy for the Fragment

b) To handle the Fragment’s visible state

c) To clean up resources when the Fragment is detached from its Activity

d) To finalize initialization once the Activity is created

Answer: c) To clean up resources when the Fragment is detached from its Activity

Explanation:The onDetach() method is called when the Fragment is detached from its
Activity, allowing for cleanup of any remaining resources.

30. In the lifecycle of a Service, which method is called to clean up resources before the Service
is destroyed?

a) onCreate()

b) onStartCommand()

c) onBind()

d) onDestroy()

Answer: d) onDestroy()
Explanation: The onDestroy() method is called to clean up resources before the Service is
destroyed, allowing for the release of resources and cleanup of any remaining tasks.

31. Which lifecycle method is called when an Activity is about to enter the background, but has
not yet stopped?

a) onPause()

b) onStop()

c) onDestroy()

d) onRestart()

Answer: a) onPause()

Explanation: The onPause() method is called when the Activity is about to enter the
background but has not yet stopped, allowing for any necessary operations such as saving data.

32. Which lifecycle method is called after onPause() when the Activity is no longer visible to the
user?

a) onCreate()

b) onStart()

c) onStop()

d) onDestroy()

Answer: c) onStop()

Explanation: The onStop() method is called after onPause() when the Activity is no longer
visible to the user, indicating that the Activity is no longer in the foreground.

33. What is the sequence of lifecycle methods called when an Activity is brought to the
foreground from a stopped state?

a) onCreate(), onStart(), onResume()

b) onRestart(), onStart(), onResume()

c) onRestart(), onResume(), onStart()

d) onStart(), onRestart(), onResume()

Answer: b) onRestart(), onStart(), onResume()


Explanation: When an Activity is brought to the foreground from a stopped state, the
sequence of lifecycle methods called is onRestart(), followed by onStart(), and then onResume().

34. Which lifecycle method in a Fragment is called when it is being detached from its parent
Activity?

a) onDestroy()

b) onDestroyView()

c) onStop()

d) onDetach()

Answer: d) onDetach()

Explanation: The onDetach() method is called when the Fragment is being detached from
its parent Activity, allowing for cleanup of any remaining resources.

35. Which lifecycle method is used to save the state of an Activity before it is destroyed?

a) onPause()

b) onSaveInstanceState()

c) onStop()

d) onRestart()

Answer: b) onSaveInstanceState()

Explanation: The onSaveInstanceState() method is used to save the state of an Activity


before it is destroyed, allowing the Activity to restore its state when it is recreated.

36. What is the purpose of the onLowMemory() method in an Activity’s lifecycle?

a) To handle configuration changes

b) To clean up resources when the system is running low on memory

c) To save the state of the Activity

d) To restart the Activity

Answer: b) To clean up resources when the system is running low on memory

Explanation: The onLowMemory() method is called when the system is running low on
memory, allowing the Activity to clean up resources to avoid being killed by the system.
37. Which method is called in a Service when it is no longer used and is being shut down?

a) onCreate()

b) onStartCommand()

c) onBind()

d) onDestroy()

Answer: d) onDestroy()

Explanation: The onDestroy() method is called in a Service when it is no longer used and is
being shut down, allowing for cleanup of resources.

38. What method in an Activity’s lifecycle is called when the device orientation changes?

a) onPause()

b) onStop()

c) onSaveInstanceState()

d) onConfigurationChanged()

Answer: d) onConfigurationChanged()

Explanation: The onConfigurationChanged() method is called when the device orientation


changes, allowing the Activity to handle the configuration change without being restarted.

39. Which method is called when an Activity is being re-created after being previously
destroyed?

a) onCreate()

b) onStart()

c) onResume()

d) onRestoreInstanceState()

Answer: d) onRestoreInstanceState()

Explanation: The onRestoreInstanceState() method is called when an Activity is being re-


created after being previously destroyed, allowing it to restore its previous state.

40. What lifecycle method is called when a Service is first bound to a client?

a) onCreate()
b) onStartCommand()

c) onBind()

d) onDestroy()

Answer: c) onBind ()

Explanation: The onBind () method is called when a Service is first bound to a client,
returning an IBinder that the client uses to communicate with the Service.

Basics of event handling in Android


1. What is the primary interface used to handle touch events in Android?

a) View.OnClickListener

b) View.OnTouchListener

c) View.OnLongClickListener

d) GestureDetector.OnGestureListener

Answer: b) View.OnTouchListener

Explanation: The View.OnTouchListener interface is used to handle touch events in Android,


allowing developers to respond to various touch interactions.

2. Which method is implemented to handle click events for a Button in Android?

a) onTouch()

b) onClick()

c) onLongClick()

d) onDoubleTap()

Answer: b) onClick()

Explanation:The onClick() method is implemented to handle click events for a Button,


defining the action that occurs when the Button is clicked.

3. Which of the following is a common method to detect long click events in Android?

a) setOnTouchListener()

b) setOnClickListener()
c) setOnLongClickListener()

d) setOnDoubleTapListener()

Answer: c) setOnLongClickListener()

Explanation: The setOnLongClickListener() method is used to detect long click events,


allowing the application to respond when the user presses and holds a view.

4. What is the role of the MotionEvent class in Android?

a) To represent touch screen motion events

b) To handle click events

c) To handle keyboard events

d) To detect gestures

Answer: a) To represent touch screen motion events

Explanation: The MotionEvent class represents touch screen motion events, providing
information about the position, type, and other characteristics of the touch event.

5. Which method in the View class is commonly overridden to handle touch events directly?

a) onClick()

b) onLongClick()

c) onTouchEvent()

d) onDoubleTap()

Answer: c) onTouchEvent()

Explanation: The onTouchEvent() method in the View class is commonly overridden to


handle touch events directly, allowing custom handling of touch interactions.

6. What is the purpose of the GestureDetector class in Android?

a) To handle click events

b) To detect and interpret gestures

c) To handle keyboard events

d) To manage view hierarchies


Answer: b) To detect and interpret gestures

Explanation: The GestureDetector class is used to detect and interpret gestures, simplifying
the process of handling complex touch interactions like swipes and double taps.

7. Which GestureDetector.OnGestureListener method is called when a fling gesture is detected?

a) onScroll ()

b) onLongPress ()

c) onFling ()

d) onSingleTapUp()

Answer c) onFling()

Explanation: The onFling() method in the GestureDetector.OnGestureListener interface is


called when a fling gesture is detected, allowing the application to respond to quick swiping
motions.

8. How can you detect a double-tap gesture in Android?

a) Using View.OnClickListener

b) Using View.OnTouchListener

c) Using GestureDetector.OnDoubleTapListener

d) Using View.OnLongClickListener

Answer: c) Using GestureDetector.OnDoubleTapListener

Explanation: The GestureDetector.OnDoubleTapListener interface is used to detect double-


tap gestures, providing methods to handle double-tap events and their various states.

9. What does the ACTION_DOWN constant in the MotionEvent class represent?

a) The start of a touch event

b) A movement event during a touch

c) The end of a touch event

d) A long press event

Answer: a) The start of a touch event


Explanation: The ACTION_DOWN constant in the MotionEvent class represents the start
of a touch event, indicating that the user has started to touch the screen.

10. Which method is used to handle key events in an Activity?

a) onKeyDown()

b) onTouchEvent()

c) onClick()

d) onLongClick()

Answer: a) onKeyDown()

Explanation: The onKeyDown() method is used to handle key events in an Activity,


allowing the application to respond to physical key presses.

11. How can you handle multiple touch points in Android?

a) Using View.OnClickListener

b) Using View.OnTouchListener with MotionEvent

c) Using View.OnLongClickListener

d) Using GestureDetector.OnDoubleTapListener

Answer: b) Using View.OnTouchListener with MotionEvent

Explanation: Multiple touch points can be handled using View.OnTouchListener with


MotionEvent, which provides information about each touch point through its methods.

12. Which method in GestureDetector.OnGestureListener is called when a scroll gesture is


detected?

a) onFling()

b) onScroll()

c) onLongPress()

d) onSingleTapUp()

Answer: b) onScroll()

Explanation: The onScroll() method in the GestureDetector.OnGestureListener interface is


called when a scroll gesture is detected, allowing the application to handle dragging motions.
13. What does the MotionEvent.ACTION_MOVE constant indicate?

a) The start of a touch event

b) A movement event during a touch

c) The end of a touch event

d) A long press event

Answer: b) A movement event during a touch

Explanation: The MotionEvent.ACTION_MOVE constant indicates a movement event


during a touch, providing updates about the position of the touch as it moves.

14. How do you handle a single tap gesture in Android?

a) Implement View.OnClickListener

b) Implement View.OnTouchListener

c) Implement GestureDetector.OnGestureListener

d) Implement GestureDetector.OnDoubleTapListener

Answer: c) Implement GestureDetector.OnGestureListener

Explanation: A single tap gesture can be handled by implementing


GestureDetector.OnGestureListener, specifically using the onSingleTapUp() method.

15. Which method is called when a user touches and holds a view in Android?

a) onClick()

b) onTouch()

c) onLongClick()

d) onDoubleTap()

Answer: c) onLongClick()

Explanation: The onLongClick() method is called when a user touches and holds a view,
allowing the application to respond to long press events.
16. Which class in Android is specifically designed to detect common gestures such as double-
taps and swipes?

a) View.OnClickListener

b) MotionEvent

c) GestureDetector

d) KeyEvent

Answer: c) GestureDetector

Explanation: The GestureDetector class is specifically designed to detect common gestures


such as double-taps and swipes, providing an easy way to handle these interactions.

17. What does the onSingleTapConfirmed() method in GestureDetector.OnDoubleTapListener


do?

a) Handles double-tap events

b) Handles long press events

c) Confirms a single tap has occurred without a double-tap

d) Handles swipe events

Answer: c) Confirms a single tap has occurred without a double-tap

Explanation: The onSingleTapConfirmed() method is called when a single tap has been
confirmed, meaning it is not followed by a second tap that would make it a double-tap.

18. Which MotionEvent constant represents the user lifting their finger off the screen?

a) ACTION_DOWN

b) ACTION_MOVE

c) ACTION_UP

d) ACTION_CANCEL

Answer: c) ACTION_UP

Explanation: The ACTION_UP constant in the MotionEvent class represents the user lifting
their finger off the screen, signaling the end of a touch event.

19. Which method is used to handle the initial press of a hardware key on an Android device?
a) onKeyDown()

b) onKeyUp()

c) onKeyLongPress()

d) onTouchEvent()

Answer: a) onKeyDown()

Explanation: The onKeyDown() method is used to handle the initial press of a hardware
key, allowing the application to respond to key press events.

20. In the context of Android event handling, what is the purpose of the setOnClickListener()
method?

a) To handle touch events

b) To handle click events

c) To handle long click events

d) To handle key events

Answer: b) To handle click events

Explanation: The setOnClickListener() method is used to handle click events for a view,
specifying the behavior that should occur when the view is clicked.

21. Which method of the MotionEvent class returns the X coordinate of a touch event?

a) getX()

b) getY()

c) getAction()

d) getPointerCount()

Answer: a) getX()

Explanation: The getX() method of the MotionEvent class returns the X coordinate of a
touch event, indicating the horizontal position of the touch on the screen.

22. What is the primary use of the setOnTouchListener() method in Android?

a) To handle click events


b) To handle touch events

c) To handle long click events

d) To handle key events

Answer: b) To handle touch events

Explanation: The setOnTouchListener() method is used to handle touch events for a view,
allowing custom behavior in response to touch interactions.

23. How can you detect a swipe gesture in Android?

a) Using View.OnClickListener

b) Using View.OnTouchListener

c) Using GestureDetector.OnGestureListener

d) Using View.OnLongClickListener

Answer: c) Using GestureDetector.OnGestureListener

Explanation: A swipe gesture can be detected using the GestureDetector.OnGestureListener


interface, particularly through the onFling() method.

24. Which method in the GestureDetector.OnGestureListener interface is triggered when a user


performs a long press?

a) onFling()

b) onScroll()

c) onLongPress()

d) onSingleTapUp()

Answer: c) onLongPress()

Explanation: The onLongPress() method in the GestureDetector.OnGestureListener


interface is triggered when a user performs a long press, allowing the application to handle long
press gestures.

25. What does the MotionEvent.ACTION_CANCEL constant indicate?

a) The start of a touch event


b) A movement event during a touch

c) The end of a touch event

d) The current event has been canceled

Answer: d) The current event has been canceled

Explanation: The MotionEvent.ACTION_CANCEL constant indicates that the current


touch event has been canceled, typically because the system has taken over handling the touch
event.

26. Which method should be overridden to handle multi-touch events in a custom view?

a) onClick()

b) onTouchEvent()

c) onKeyDown()

d) onLongClick()

Answer: b) onTouchEvent()

Explanation: The onTouchEvent() method should be overridden in a custom view to handle


multi-touch events, allowing the view to respond to complex touch interactions involving
multiple touch points

27. How can you handle a fling gesture in Android?

a) Implement View.OnClickListener

b) Implement View.OnTouchListener

c) Implement GestureDetector.OnGestureListener

d) Implement GestureDetector.OnDoubleTapListener

Answer: c) Implement GestureDetector.OnGestureListener

Explanation: A fling gesture can be handled by implementing


GestureDetector.OnGestureListener, specifically using the onFling() method to respond to quick
swiping motions.

28. What does the onDoubleTap() method in GestureDetector.OnDoubleTapListener handle?

a) Single tap events


b) Double-tap events

c) Long press events

d) Swipe events

Answer: b) Double-tap events

Explanation: The onDoubleTap() method in the GestureDetector.OnDoubleTapListener


interface handles double-tap events, responding when the user taps the screen twice in quick
succession.

29. Which method in the GestureDetector.OnGestureListener interface is used to handle the


initial touch down event?

a) onFling()

b) onScroll()

c) onLongPress()

d) onDown()

Answer: d) onDown()

Explanation: The onDown() method in the GestureDetector.OnGestureListener interface is


used to handle the initial touch down event, which occurs when the user first touches the screen.

30. How can you programmatically simulate a click event on a view in Android?

a) callOnClick()

b) performClick()

c) simulateClick()

d) triggerClick()

Answer: b) performClick()

Explanation: The performClick() method can be used to programmatically simulate a click


event on a view, triggering the view's click handling logic as if it were clicked by the user.

31. Which method in the GestureDetector.OnGestureListener interface handles the initial motion
event when a user starts scrolling?

a) onFling()
b) onScroll()

c) onLongPress()

d) onDown()

Answer: b) onScroll()

Explanation The onScroll() method in the GestureDetector.OnGestureListener interface


handles the initial motion event when a user starts scrolling, allowing for handling of dragging
motions.

32. In Android, what does the MotionEvent.ACTION_POINTER_DOWN constant represent?

a) The start of a single touch event

b) The movement of a touch event

c) The start of a multi-touch event

d) The end of a touch event

Answer: c) The start of a multi-touch event

Explanation: The MotionEvent.ACTION_POINTER_DOWN constant represents the start of a


multi-touch event, indicating that an additional finger has touched the screen.

33. Which method is used to detect a user's press and hold action on a view?

a) setOnClickListener()

b) setOnTouchListener()

c) setOnLongClickListener()

d) setOnGestureListener()

Answer: c) setOnLongClickListener()

Explanation: The setOnLongClickListener() method is used to detect a user's press and hold
action on a view, allowing the application to respond to long press events.

34. What method in the MotionEvent class returns the number of pointers (touch points)
currently active?

a) getPointerCount()

b) getPointerId()
c) getX()

d) getAction()

Answer: a) getPointerCount()

Explanation: The getPointerCount() method in the MotionEvent class returns the number of
pointers (touch points) currently active, which is useful for handling multi-touch events.

35. How can you detect a double-tap and then perform a specific action in Android?

a) Using View.OnClickListener

b) Using View.OnTouchListener

c) Using GestureDetector.OnDoubleTapListener

d) Using View.OnLongClickListener

Answer: c) Using GestureDetector.OnDoubleTapListener

Explanation: A double-tap can be detected using the GestureDetector.OnDoubleTapListener


interface, and specific actions can be performed in the onDoubleTap() method.

36. Which method in the GestureDetector.OnGestureListener interface is called when the user
lifts their finger off the screen during a gesture?

a) onFling()

b) onScroll()

c) onSingleTapUp()

d) onShowPress()

Answer: c) onSingleTapUp()

Explanation: The onSingleTapUp() method in the GestureDetector.OnGestureListener


interface is called when the user lifts their finger off the screen during a gesture, typically
indicating the end of a single tap.

37. What does the MotionEvent.ACTION_POINTER_UP constant indicate?

a) The start of a single touch event

b) The movement of a touch event


c) The start of a multi-touch event

d) The end of a multi-touch event

Answer: d) The end of a multi-touch event

Explanation: The MotionEvent.ACTION_POINTER_UP constant indicates the end of a


multi-touch event, signaling that one of the additional fingers has been lifted from the screen.

38. How can you handle a swipe gesture in Android using GestureDetector?

a) Implement View.OnClickListener

b) Implement View.OnTouchListener

c) Implement GestureDetector.OnGestureListener and override onFling()

d) Implement GestureDetector.OnDoubleTapListener

Answer: c) Implement GestureDetector.OnGestureListener and override onFling()

Explanation: A swipe gesture can be handled by implementing GestureDetector.


OnGestureListener and overriding the onFling() method to respond to quick swiping motions.

39. Which method in the GestureDetector.OnGestureListener interface is called when a user


performs a short, quick tap?

a) onFling()

b) onScroll()

c) onSingleTapUp()

d) onDoubleTap()

Answer: c) onSingleTapUp()

Explanation: The onSingleTapUp() method is called when a user performs a short, quick
tap, typically used to handle single tap gestures.

40. What does the onShowPress() method in GestureDetector.OnGestureListener handle?

a) Detects a long press gesture

b) Provides visual feedback during a touch event

c) Handles the start of a fling gesture

d) Handles the end of a swipe gesture


Answer: b) Provides visual feedback during a touch event

Explanation: The onShowPress() method in GestureDetector.OnGestureListener handles


providing visual feedback during a touch event, indicating that the user has started to press on
the screen.

Graphics and multimedia support in Android


1. Which class in Android is primarily used to draw graphics on a canvas?

a) Drawable

b) Paint

c) Canvas

d) View

Answer: c) Canvas

Explanation: The Canvas class in Android is used to draw graphics on a drawable surface,
providing methods to draw shapes, text, and images.

2. What method is commonly overridden to perform custom drawing in a custom view?

a) onLayout()

b) onMeasure()

c) onDraw()

d) onSizeChanged()

Answer: c) onDraw()

Explanation: The onDraw() method is overridden in a custom view to perform custom


drawing using a Canvas object, allowing the developer to define the view's visual content.

3. Which class in Android is used to manage and play audio files?

a) AudioManager

b) MediaPlayer

c) SoundPool

d) AudioTrack
Answer: b) MediaPlayer

Explanation: The MediaPlayer class is used to manage and play audio and video files,
providing methods to control playback and handle various media events.

4. What method is used to start playback of an audio file in MediaPlayer?

a) start()

b) play()

c) resume()

d) begin()

Answer: a) start()

Explanation: The start() method is used to begin playback of an audio or video file in
MediaPlayer, initiating the media playback process.

5. Which format is supported by the MediaPlayer class for audio playback in Android?

a) MP3

b) WAV

c) AAC

d) All of the above

Answer: d) All of the above

Explanation: The MediaPlayer class supports various audio formats, including MP3, WAV,
and AAC, enabling it to play a wide range of audio files.

6. How can you load and play a short sound effect efficiently in Android?

a) Using MediaPlayer

b) Using SoundPool

c) Using AudioManager

d) Using AudioTrack

Answer: b) Using SoundPool

Explanation: The SoundPool class is designed for loading and playing short sound effects
efficiently, providing low-latency audio playback suitable for games and interactive applications.
7. Which method in the Canvas class is used to draw a rectangle on the screen?

a) drawRect()

b) drawLine()

c) drawPath()

d) drawOval()

Answer: a) drawRect()

Explanation: The drawRect() method in the Canvas class is used to draw a rectangle on the
screen, specifying the coordinates and dimensions of the rectangle.

8. What class in Android is used to create and manipulate images?

a) ImageView

b) Bitmap

c) Drawable

d) Canvas

Answer: b) Bitmap

Explanation: The Bitmap class is used to create and manipulate images in Android,
providing methods to handle image data and perform image processing.

9. Which method in MediaPlayer is used to prepare the player for playback asynchronously?

a) prepare()

b) prepareAsync()

c) initialize()

d) setup()

Answer: b) prepareAsync()

Explanation The prepareAsync() method in MediaPlayer is used to prepare the player for
playback asynchronously, allowing the application to continue running while the media is being
prepared.

10. How can you draw text on a Canvas in Android?

a) drawText()
b) drawString()

c) writeText()

d) renderText()

Answer: a) drawText()

Explanation: The drawText() method in the Canvas class is used to draw text on the canvas,
specifying the text, position, and paint attributes.

11. What method is used to release the resources associated with a MediaPlayer object?

a) stop()

b) pause()

c) release()

d) close()

Answer: c) release()

Explanation: The release() method is used to release the resources associated with a
MediaPlayer object, freeing up memory and other resources used by the media player.

12. Which Android class provides a low-level interface for playing sound files directly?

a) MediaPlayer

b) SoundPool

c) AudioTrack

d) AudioManager

Answer: c) AudioTrack

Explanation: The AudioTrack class provides a low-level interface for playing sound files
directly, offering more control over audio playback than higher-level classes like MediaPlayer

13. Which method in Bitmap class is used to create a new bitmap that is a scaled version of an
existing bitmap?

a) createScaledBitmap()

b) scaleBitmap()

c) resizeBitmap()
d) transformBitmap()

Answer: a) createScaledBitmap()

Explanation: The createScaledBitmap() method in the Bitmap class is used to create a new
bitmap that is a scaled version of an existing bitmap, specifying the new dimensions and scaling
options.

14. What is the purpose of the setVolume() method in MediaPlayer?

a) To mute the audio playback

b) To adjust the playback speed

c) To set the volume level for audio playback

d) To balance the audio channels

Answer: c) To set the volume level for audio playback

Explanation: The setVolume() method in MediaPlayer is used to set the volume level for
audio playback, allowing control over the audio output level.

15. How can you handle the completion of audio playback in MediaPlayer?

a) Implement OnCompletionListener and override onCompletion()

b) Implement OnErrorListener and override onError()

c) Implement OnInfoListener and override onInfo()

d) Implement OnPreparedListener and override onPrepared()

Answer: a) Implement OnCompletionListener and override onCompletion()

Explanation: To handle the completion of audio playback in MediaPlayer, you implement


the OnCompletionListener interface and override the onCompletion() method, which is called

16. Which method in the Paint class is used to set the color for drawing?

a) setColor()

b) setPaintColor()

c) setBrushColor()

d) setFillColor()

Answer: a) setColor()
Explanation: The setColor() method in the Paint class is used to set the color for drawing,
specifying the color to be used for subsequent drawing operations.

17. How can you play a video file within an Android application?

a) Using MediaPlayer with a SurfaceView

b) Using SoundPool with a VideoView

c) Using AudioManager with a TextureView

d) Using AudioTrack with a VideoView

Answer: a) Using MediaPlayer with a SurfaceView

Explanation: To play video files in an Android application, MediaPlayer can be used in


combination with a SurfaceView or VideoView to provide the necessary surface for video
playback.

20. Which of the following classes is used to decode and encode images in Android?

a) BitmapFactory

b) ImageView

c) Drawable

d) Canvas

Answer: a) BitmapFactory

Explanation: The BitmapFactory class is used to decode and encode images in Android,
providing methods to create Bitmap objects from various sources such as files, streams, and byte
arrays.

21. How do you handle the resizing of a video to fit within a VideoView?

a) setAspectRatio()

b) setVideoSize()

c) setLayoutParams()

d) setVideoScalingMode()

Answer: b) setVideoSize()
Explanation:The setVideoSize() method in MediaPlayer can be used to handle the resizing of
a video to fit within a VideoView by specifying the desired width and height for the video
playback.

22. Which method in the SoundPool class is used to load a sound from a resource file?

a) loadSound()

b) load()

c) play()

d) addSound()

Answer: b) load()

Explanation: The load() method in the SoundPool class is used to load a sound from a
resource file, returning a sound ID that can be used to play the sound later.

23. Which method in the Paint class is used to set the style for drawing (e.g., fill, stroke)?

a) setStyle()

b) setPaintStyle()

c) setDrawingStyle()

d) setDrawStyle()

Answer: a) setStyle()

Explanation: The setStyle() method in the Paint class is used to set the style for drawing, such
as fill or stroke, which determines how shapes and text are rendered.

24. How do you set the looping behavior for a MediaPlayer object?

a) setLoop()

b) setRepeat()

c) setLooping()

d) setRepeating()

Answer: c) setLooping()

Explanation: The setLooping() method in MediaPlayer is used to set the looping behavior,
specifying whether the media should restart automatically after reaching the end.
25. What is the purpose of the invalidate () method in a custom view?

a) To redraw the view

b) To stop drawing the view

c) To clear the view's canvas

d) To save the view's current state

Answer: a) To redraw the view

Explanation: The invalidate() method in a custom view is used to request a redraw of the view,
causing the onDraw() method to be called and updating the view's appearance.

26. Which method in the MediaPlayer class is used to pause the playback of audio or video?

a) stop()

b) pause()

c) halt()

d) break()

Answer: b) pause()

Explanation: The pause() method in the MediaPlayer class is used to pause the playback of
audio or video, allowing the playback to be resumed later from the same position.

27. What method is used to draw a circle on a Canvas in Android?

a) drawRect()

b) drawCircle()

c) drawOval()

d) drawArc()

Answer: b) drawCircle()

Explanation: The drawCircle() method in the Canvas class is used to draw a circle on the
canvas, specifying the center coordinates and radius of the circle.

28. How can you adjust the playback speed of a MediaPlayer object?

a) setSpeed()
b) setPlaybackSpeed()

c) setRate()

d) setPlaybackParams()

Answer: d) setPlaybackParams()

Explanation: The setPlaybackParams() method in MediaPlayer is used to adjust the playback


speed, allowing for changes in the playback rate of audio or video content.

29. Which method in the Bitmap class is used to create a bitmap from a drawable resource?

a) createFromResource()

b) decodeResource()

c) loadFromResource()

d) getResourceBitmap()

Answer: b) decodeResource()

Explanation: The decodeResource() method in the Bitmap class is used to create a bitmap
from a drawable resource, providing a simple way to decode images from resources.

30. What is the purpose of the setDataSource() method in MediaPlayer?

a) To set the audio or video file to be played

b) To set the volume level

c) To set the display surface for video playback

d) To set the playback speed

Answer: a) To set the audio or video file to be played

Explanation: The setDataSource() method in MediaPlayer is used to set the audio or video
file to be played, specifying the source of the media content.

31. Which method in the Paint class is used to set the text size for drawing text?

a) setTextSize()

b) setFontSize()

c) setSize()
d) setTextFontSize()

Answer: a) setTextSize()

Explanation:The setTextSize() method in the Paint class is used to set the text size for drawing
text, specifying the size of the text in pixels.

32. How do you handle touch events in a custom view for drawing purposes?

a) Override the onTouchEvent() method

b) Override the onDraw() method

c) Override the onLayout() method

d) Override the onMeasure() method

Answer: a) Override the onTouchEvent() method

Explanation: To handle touch events in a custom view for drawing purposes, you override
the onTouchEvent() method, allowing you to respond to touch interactions and update the view
accordingly.

33. Which method in the SoundPool class is used to play a loaded sound?

a) start()

b) play()

c) resume()

d) trigger()

Answer: b) play()

Explanation: The play() method in the SoundPool class is used to play a loaded sound,
specifying the sound ID, volume, and playback rate.

34. What method is used to stop the playback of a MediaPlayer object?

a) stop()

b) pause()

c) halt()

d) terminate()

Answer: a) stop()
Explanation: The stop() method in MediaPlayer is used to stop the playback of audio or video,
resetting the player to its uninitialized state.

35. How can you optimize bitmap memory usage when loading large images in Android?

a) By using BitmapFactory.Options and setting inSampleSize

b) By using BitmapFactory.Options and setting inMutable

c) By using BitmapFactory.Options and setting inScaled

d) By using BitmapFactory.Options and setting inDither

Answer: a) By using BitmapFactory.Options and setting inSampleSize

Explanation: To optimize bitmap memory usage when loading large images, you can use
BitmapFactory.Options and set the inSampleSize property, which reduces the image resolution
and decreases memory consumption.

36. Which class provides a surface for direct drawing and manipulation of pixels in Android?

a) SurfaceView

b) TextureView

c) ImageView

d) VideoView

Answer: b) TextureView

Explanation: The TextureView class provides a surface for direct drawing and manipulation
of pixels in Android, allowing for custom

37. Which class in Android provides the capability to play sounds from URI sources?

a) MediaPlayer

b) SoundPool

c) AudioTrack

d) AudioManager

Answer: a) MediaPlayer

Explanation: MediaPlayer can handle playback of sounds from various URI sources, including
streaming audio and video content from the internet.
38. What is the purpose of the getFrameAtTime() method in MediaMetadataRetriever?

a) To retrieve audio metadata

b) To capture a frame from a video

c) To adjust playback speed

d) To synchronize audio and video

Answer: b) To capture a frame from a video

Explanation: The getFrameAtTime() method in MediaMetadataRetriever is used to capture


a frame from a video at a specified time, allowing for frame extraction and manipulation.

39. Which class is used to create a graphical user interface (GUI) element that displays a
drawable resource?

a) ImageView

b) TextView

c) Button

d) LinearLayout

Answer: a) ImageView

Explanation: The ImageView class is used to create a GUI element that displays a drawable
resource, such as an image or icon, within an Android application.

40. How can you reduce the memory consumption of a bitmap when decoding from a resource
file?

a) By using BitmapFactory.Options and setting inPreferredConfig to ARGB_4444

b) By using BitmapFactory.Options and setting inSampleSize

c) By using BitmapFactory.Options and setting inDither to true

d) By using BitmapFactory.Options and setting inJustDecodeBounds to true

Answer: b) By using BitmapFactory.Options and setting inSampleSize


Basic skills of using an integrated development environment (Android
Studio) and Android Software Development Kit (SDK) for implementing
simple Android applications
1. When creating a new Android project in Android Studio, which of the following files contains
the metadata and configuration information for the application?

a) app/src/main/AndroidManifest.xml

b) app/build.gradle

c) app/src/main/java/MainActivity.java

d) app/src/main/res/layout/activity_main.xml

Answer: a) app/src/main/AndroidManifest.xml

Explanation: The AndroidManifest.xml file contains essential metadata about the application,
including its package name, permissions, activities, and services.

2. Which of the following components in Android Studio is primarily used for designing the user
interface of an Android application?

a) Layout Editor

b) Project Navigator

c) Code Editor

d) Gradle Console

Answer: a) Layout Editor

Explanation: The Layout Editor in Android Studio provides a visual interface for designing and
arranging UI elements within XML layout files.

3. In Android Studio, which menu option is used to run the application on a connected device or
emulator?

a) Run > Run 'app'

b) Tools > Run Application

c) File > Run Application

d) Build > Deploy


Answer: a) Run > Run 'app'

Explanation: This menu option is used to compile the application and deploy it to a connected
device or emulator for testing.

4. What is the purpose of the Gradle build system in Android development?

a) To design the user interface of the application

b) To manage project dependencies and build configurations

c) To write code for the application's functionality

d) To debug and test the application

**Answer: b) To manage project dependencies and build configurations

**Explanation: Gradle is a build automation tool that is used to manage project dependencies,
configure build settings, and automate the build process in Android development.

5. Which directory in an Android project contains the Java source code files for the application?

a) app/src/main/assets

b) app/src/main/java

c) app/src/main/res

d) app/src/main/libs

**Answer: b) app/src/main/java

**Explanation: The Java source code files for the application are located in the "java"
directory within the "main" directory of the "src" directory.

6. In Android Studio, what is the purpose of the "Build Variants" panel?

a) To manage different versions of the application

b) To configure build settings and dependencies

c) To select the target device for deployment

d) To switch between different product flavors and build types

**Answer d) To switch between different product flavors and build types

**Explanation: The "Build Variants" panel in Android Studio allows developers to switch
between different product flavors and build types configured for the project.
7. Which file in an Android project contains the configuration settings and dependencies for the
project?

a) AndroidManifest.xml

b) build.gradle (Project)

c) build.gradle (Module)

d) settings.gradle

**Answer c) build.gradle (Module)

**Explanation:The build.gradle file located in the module directory contains the configuration
settings, dependencies, and build scripts specific to that module or application component.

8. What is the purpose of the "Run" menu in Android Studio?

a) To compile and build the application

b) To deploy the application to a device or emulator

c) To analyze code quality and performance

d) To configure project settings and build variants

**Answer: b) To deploy the application to a device or emulator

**Explanation: The "Run" menu in Android Studio provides options for deploying and
running the application on a connected device or emulator.

9. Which tool in Android Studio is used to manage project dependencies and download required
libraries?

a) SDK Manager

b) AVD Manager

c) File Explorer

d) Project Structure Dialog

**Answer: a) SDK Manager

**Explanation:* The SDK Manager in Android Studio is used to manage project


dependencies, including downloading required libraries and components for Android
development.
10. In Android Studio, what is the purpose of the "Logcat" panel?

a) To view system logs and debug messages

b) To manage project resources and assets

c) To analyze code quality and performance

d) To view device specifications and configurations

**Answer:** a) To view system logs and debug messages

**Explanation: The "Logcat" panel in Android Studio displays system logs, debug messages,
and runtime information from the connected device or emulator during application execution.

11. What is the purpose of the "activity_main.xml" file in an Android project?

a) To define the application's main activity

b) To configure project settings and dependencies

c) To manage project resources and assets

d) To design the layout of the main activity's user interface

**Answer: d) To design the layout of the main activity's user interface

**Explanation: The "activity_main.xml" file contains the layout XML code used to design the
user interface of the main activity in an Android application.

12. Which of the following is NOT a valid layout file format used in Android development?

a) .xml

b) .java

c) .kt

d) .json

**Answer:** d) .json

**Explanation: While XML (.xml) and Kotlin (.kt) are commonly used for layout and code
files in Android development, JSON (.json) is not a standard format for defining layouts.

13. In Android Studio, which tool is used to debug and analyze the performance of an Android
application?
a) Profiler

b) Logcat

c) Debugger

d) Android Device Monitor

**Answer:** a) Profiler

**Explanation:** The Profiler tool in Android Studio is used to analyze the performance of
an Android application, including CPU usage, memory allocation, and network activity.

14. What is the purpose of the "strings.xml" file in an Android project?

a) To define global constants and variables

b) To store string literals and resources used in the application

c) To configure project settings and dependencies

d) To manage project resources and assets

**Answer: b) To store string literals and resources used in the application

**Explanation: The "strings.xml" file is used to store string literals and resources, allowing
for easy localization and management of text used in the application.

15. Which of the following Android Studio features provides real-time suggestions, code
completion, and error checking while coding?

a) Logcat

b) Debugger

c) Code Editor

d) Lint Analyzer

**Answer:** c) Code Editor

**Explanation:** The Code Editor in Android Studio provides real-time suggestions, code
completion, and error checking features to enhance productivity and code quality while coding.

16. What is the purpose of the "drawable" directory in an Android project?

a) To store layout XML files

b) To store drawable resources such as images and icons


c) To store Java source code files

d) To store localization strings

**Answer: b) To store drawable resources such as images and icons

**Explanation: The "drawable" directory is used to store drawable resources such as images,
icons, and graphics used in the user interface of the application.

17. Which of the following tools is used to create and manage virtual devices for testing Android
applications?

a) SDK Manager

b) AVD Manager

c) Gradle Console

d) Project Structure Dialog

**Answer: b) AVD Manager

**Explanation:*The AVD Manager (Android Virtual Device Manager) is used to create and
manage virtual devices (emulators) for testing Android applications on different device
configurations.

18. In Android Studio, what is the purpose of the "Build" menu?

a) To compile and build the application

b) To deploy the application to a device or emulator

c) To analyze code quality and performance

d) To configure project settings and build variants

**Answer:*a) To compile and build the application

**Explanation:*The "Build" menu in Android Studio provides options for compiling and
building the application, including options for cleaning and rebuilding the project.

19. Which file in an Android project is used to define custom styles and themes for the
application's user interface?

a) AndroidManifest.xml

b) styles.xml
c) themes.xml

d) colors.xml

**Answer b) styles.xml

**Explanation: The "styles.xml" file is used to define custom styles and themes for the
application's user interface, allowing for consistent visual styling across the app.

20. In Android Studio, which of the following is NOT a valid code inspection tool?

a) Lint

b) Debugger

c) Error Prone

d) FindBugs

**Answer: b) Debugger

**Explanation: While the Debugger is a debugging tool, Lint, Error Prone, and FindBugs are
code inspection tools used to analyze and improve code quality in Android Studio.

21. What is the purpose of the "Android SDK Manager" in Android Studio?

a) To manage project dependencies and libraries

b) To create and manage virtual devices for testing

c) To download and update Android SDK components

d) To configure build settings and flavors

**Answer: c) To download and update Android SDK components

**Explanation: The Android SDK Manager is used to download and update Android SDK
components, including platform tools, system images, and additional SDK packages required for
Android development.

22. Which of the following components is NOT typically found in an Android Manifest file?

a) Activity

b) Layout

c) Service

d) BroadcastReceiver
**Answer: b) Layout

**Explanation: The Android Manifest file typically contains declarations for activities,
services, broadcast receivers, content providers, permissions, and other essential information
about the application.

25. What is the primary use of the "Profiler" tool in Android Studio?

a) To design user interfaces

b) To analyze code quality

c) To debug application crashes

d) To analyze performance and resource usage

**Answer: d) To analyze performance and resource usage

Explanation: The Profiler tool in Android Studio is used to analyze the performance and resource
usage of an Android application, including CPU, memory, and network usage.

26. Which of the following options is NOT a valid method to optimize memory usage in Android
development?

a) Using lightweight data structures

b) Releasing unused resources

c) Increasing the app's APK size

d) Using efficient algorithms

**Answer: c) Increasing the app's APK size

**Explanation: Increasing the app's APK size would not directly optimize memory usage;
instead, it might increase resource consumption.

27. What does the term "Activity" refer to in the context of Android development?

a) A class that represents a user interface screen

b) A background service that performs long-running tasks

c) A component used to manage database operations

d) A layout file that defines the user interface

**Answer: a) A class that represents a user interface screen


**Explanation: In Android development, an Activity is a class that represents a single screen
with a user interface. It typically corresponds to one activity of the user interacting with the app.

28. What is the purpose of the "assets" directory in an Android project?

a) To store layout XML files

b) To store drawable resources such as images

c) To store static files that are bundled with the app

d) To store Java source code files

**Answer:** c) To store static files that are bundled with the app

**Explanation: The "assets" directory is used to store static files that are bundled with the app,
such as HTML files, text files, or data files.

29. Which tool in Android Studio is used to manage project dependencies and external libraries?

a) SDK Manager

b) AVD Manager

c) Dependency Manager

d) Project Structure Dialog

**Answer: d) Project Structure Dialog

**Explanation: The Project Structure Dialog in Android Studio is used to manage project
dependencies, external libraries, and module settings for the project.

30. What is the purpose of the "res" directory in an Android project?

a) To store Java source code files

b) To store static assets and resources

c) To store layout XML files

d) To store configuration files

**Answer b) To store static assets and resources

**Explanation: The "res" directory in an Android project is used to store static assets and
resources such as layouts, drawables, strings, and other resources used by the application.

You might also like