Basic components of an Android application
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.
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.
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.
a) Activity
b) Service
c) BroadcastReceiver
d) ContentProvider
Answer: c) BroadcastReceiver
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.
a) Activity
b) Service
c) BroadcastReceiver
d) ContentProvider
Answer d) ContentProvider
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.
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
12. What is the primary function of the activity_main.xml file in an Android application?
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.
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
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.
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.
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.
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 "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.
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.
Explanation: The "res" directory contains various types of resources used in an Android
application, including layouts, drawables, values, and more..
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.
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()
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.
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.
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?
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 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()
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()
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.
a) View.OnClickListener
b) View.OnTouchListener
c) View.OnLongClickListener
d) GestureDetector.OnGestureListener
Answer: b) View.OnTouchListener
a) onTouch()
b) onClick()
c) onLongClick()
d) onDoubleTap()
Answer: b) onClick()
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()
d) To detect gestures
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 GestureDetector class is used to detect and interpret gestures, simplifying
the process of handling complex touch interactions like swipes and double taps.
a) onScroll ()
b) onLongPress ()
c) onFling ()
d) onSingleTapUp()
Answer c) onFling()
a) Using View.OnClickListener
b) Using View.OnTouchListener
c) Using GestureDetector.OnDoubleTapListener
d) Using View.OnLongClickListener
a) onKeyDown()
b) onTouchEvent()
c) onClick()
d) onLongClick()
Answer: a) onKeyDown()
a) Using View.OnClickListener
c) Using View.OnLongClickListener
d) Using GestureDetector.OnDoubleTapListener
a) onFling()
b) onScroll()
c) onLongPress()
d) onSingleTapUp()
Answer: b) onScroll()
a) Implement View.OnClickListener
b) Implement View.OnTouchListener
c) Implement GestureDetector.OnGestureListener
d) Implement GestureDetector.OnDoubleTapListener
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 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?
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.
Explanation: The setOnTouchListener() method is used to handle touch events for a view,
allowing custom behavior in response to touch interactions.
a) Using View.OnClickListener
b) Using View.OnTouchListener
c) Using GestureDetector.OnGestureListener
d) Using View.OnLongClickListener
a) onFling()
b) onScroll()
c) onLongPress()
d) onSingleTapUp()
Answer: c) onLongPress()
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()
a) Implement View.OnClickListener
b) Implement View.OnTouchListener
c) Implement GestureDetector.OnGestureListener
d) Implement GestureDetector.OnDoubleTapListener
d) Swipe events
a) onFling()
b) onScroll()
c) onLongPress()
d) onDown()
Answer: d) onDown()
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()
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()
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
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()
38. How can you handle a swipe gesture in Android using GestureDetector?
a) Implement View.OnClickListener
b) Implement View.OnTouchListener
d) Implement GestureDetector.OnDoubleTapListener
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.
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.
a) onLayout()
b) onMeasure()
c) onDraw()
d) onSizeChanged()
Answer: c) onDraw()
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.
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
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
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.
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.
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.
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?
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?
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?
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.
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()
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.
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?
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.
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?
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?
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) 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
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?
Explanation: This menu option is used to compile the application and deploy it to a connected
device or emulator for testing.
**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.
**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
**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.
**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
**Explanation: The "Logcat" panel in Android Studio displays system logs, debug messages,
and runtime information from the connected device or emulator during application execution.
**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
**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.
**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
**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.
**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
**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.
**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?
**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?
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?
**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?
**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
**Explanation: The Project Structure Dialog in Android Studio is used to manage project
dependencies, external libraries, and module settings for the project.
**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.