Android How to Program Chapter 05
Download file with the answers
Android How to Program Chapter 05
1 file(s) 106.21 KB
If you are not a member register here to download this file
Chapter 5 Doodlz App
5.1 Introduction
Q1. Android requires the user’s permission to allow an app to save files. In Android 6.0, the app ________.
a. prompts the user at installation time with a complete list of permissions the app requires.
b. prompts the user at installation time and execution time with a complete list of permissions the app requires.
c. requests each permission individually at execution time, only when the permission is required to perform a given task for the first time.
d. None of the above.
5.2 Test-Driving the Doodlz App in an Android Virtual Device (AVD)
Q1. Colors are defined using the ARGB color scheme in which the ________ (i.e., transparency), red, green and blue components, respectively, are specified by inte-gers in the range 0–255.
a. transparency
b. translucency
c. alpha
d. None of the above.
5.3.1 Activity and Fragment Lifecycle Methods
Q1. Which of the following statements is false?
a. A Fragment’s lifecycle is tied to that of its parent Activity.
b. There are six Activity lifecycle methods that have corresponding Fragment lifecycle methods—onCreate, onStart, onResume, onPause, onStop and onDestroy.
c. When the system calls life cycle methods on an Activity, it will also call the corresponding methods (and potentially other Fragment lifecycle methods) on all of the Activity’s attached Fragments.
d. An Activity’s onResume method is called when a Fragment is on the screen and ready for the user to interact with it.
Q2. Which of the following statements is false?
a. When an Activity hosts Fragments and the Activity is resumed, all of its Fragments’ onResume methods are called.
b. An Activity’s onPause method is called when another Activity receives the focus, which pauses the one that loses the focus and sends it to the background.
c. When an Activity hosts Fragments and the Activity is paused, all of its Frag-ments’ onPause methods are called.
d. When an app is paused, it should ensure that listeners for sensor events are still active.
5.3.3 Using SensorManager to Listen for Accelerometer Events
Q1. Most devices have a(n) ________ for detecting device movement.
a. accelerator
b. speed sensor
c. accelerometer
d. None of the above.
5.3.5 Drawing with Canvas, Paint and Bitmap
Q1. Each drawing method in class Canvas uses an object of class ________ (pack-age android.graphics) to specify drawing characteristics, including color, line thickness, font size and more.
a. Draw
b. Characteristics
c. Settings
d. Paint
5.3.6 Processing Multiple Touch Events and Storing Lines in Paths
Q1. A ________ object (package android-.graphics) represents line segments and curves.
a. Segment
b. Line
c. Path
d. Curve
Q2. In addition to standard touch-event handling, Android 6.0 provides enhanced support for using a(n) ________ stylus with apps, including access to pressure data and which stylus button the user presses.
a. Wi-Fi
b. Bluetooth
c. NFC
d. Ethernet
5.3.7 Saving to the Device
Q1. A(n) ________ (package android-.content) enables the app to read data from and store data on a device.
a. Content-Resolver
b. Resolver
c. ContentAccessor
d. None of the above
5.3.8 Printing and the Android Support Library’s PrintHelper Class
Q1. Class ________ provides a user interface for selecting a printer, has a method for determining whether a given device supports printing and provides a method for printing a Bitmap.
a. Printer
b. PrinterUI
c. PrintHelper
d. None of the above
5.3.9 New Android 6.0 (Marshmallow) Permissions Model
Q1. Which of the following statements is false?
a. Android requires the permission an-droid.permission.WRITE_EXTERNAL_PERMISSION before an app can write to ex-ternal storage.
b. Before Android 6.0, a user was required at start time to grant in advance all per-missions that an app would ever need—this caused many people not to install certain apps.
c. With the new permissions model, the app is installed without asking for any per-missions. Instead, the user is asked to grant a permission only the first time the cor-responding feature is used.
d. Once the user grants a permission, the app has that permission until the app is reinstalled or the user changes the app’s permissions via the Android Settings app.
5.3.10 Adding Dependencies Using the Gradle Build System
Q1. Android Studio uses the ________ build system to compile your code into an APK file—the installable app. This system also handles project dependencies, such as including in the build process any libraries used by the app.
a. Buck
b. Maven
c. Bazel
d. Gradle
5.4.3 strings.xml
Q1. Google’s material design specification indicates that a Button’s text should ________.
a. use all lowercase letters
b. use all capital letters (e.g., CANCEL or SET COLOR) for languages that support them
c. use initial uppercase letters
d. None of the above
5.4.5 MainActivityFragment Menu
Q1. We use each menu item’s ________ property to specify that the menu item should be displayed on the app bar if there is room.
a. showAsAction
b. showOnActionBar
c. showIfRoom
d. None of the above
5.4.6 Adding a Permission to AndroidManifest.xml
Q1. In addition to using Android 6.0’s new permissions model in which the app asks the user to grant permissions dynamically, each app also must specify any permis-sions it uses in ________.
a. class MainActivity
b. strings.xml
c. permissions.xml
d. AndroidManifest.xml
5.7.1 package Statement, import Statements and Fields
Q1. Accelerometer information is delivered to the app as ________ values.
a. double
b. String
c. float
d. int
5.7.2 Overridden Fragment Method onCreateView
Q1. A Fragment can place items in the app’s app bar and options menu. To do so, the Fragment must call its ________ method with the argument true.
a. setHasOptionsMenu
b. setOptionsMenu
c. setMenu
d. setHasMenu
5.7.3 Methods onResume and enableAccelerometerListening
Q1. A ________ is used to register listeners for accelerometer events.
a. AccelerometerManager
b. ListenerManager
c. SensorProcessor
d. SensorManager
5.7.4 Methods onPause and disableAccelerometerListening
Q1. You use class SensorManager’s ________ method to stop listening for accel-erometer events.
a. reset
b. unregisterListener
c. stopListening
d. None of the above
5.7.5 Anonymous Inner Class for Processing Accelerometer Events
Q1. You override SensorEventListener method ________ to process accelerome-ter events. This method should handle sensor events quickly or to copy the event data because the array of sensor values is reused for each sensor event.
a. sensorChanged
b. onSensorEvent
c. onSensorChanged
d. None of the above
5.7.7 Overridden Fragment Methods onCreateOptionsMenu and onOptionsItemSelected
Q1. When the user selects a Fragment’s menu item, Fragment method ________ responds to the selection.
a. onItemSelected
b. onMenuItemSelected
c. onOptionsItemSelected
d. onMenuSelected
5.7.8 Method saveImage
Q1. If an app does not have a needed permission (such as an-droid.permission.WRITE_EXTERNAL_STORAGE), use the built-in ________ method to determine whether an explanation of why the app needs this permission should be displayed.
a. shouldShowRationale
b. shouldShowPermissionRationale
c. shouldShowRequestRationale
d. shouldShowRequestPermissionRationale
5.7.10 Methods getDoodleView and setDialogOnScreen
Q1. Which of the following statements is false?
a. When an app’s Fragments interact with one another directly, we call this a loose-ly coupled approach.
b. Generally, a parent Activity manages an app’s Fragment interactions.
c. To pass data to a Fragment, the Activity provides a Bundle of arguments.
d. Each Fragment class typically provides an interface of callback methods that its Activity implements. When the Fragment needs to notify its parent Activity of a state change, the Fragment calls the appropriate callback method.
5.8.3 Constructor
Q1. Passing true to Paint’s ________ method enables smoothing the edges of the lines.
a. setSmoothing
b. setHigherResolution
c. setAntiAlias
d. None of the above
5.8.4 Overridden View Method onSizeChanged
Q1. In apps that support both portrait and landscape orientations, onSizeChanged is called each time the user rotates the device. This could result in a new Bitmap each time the method is called. When replacing a Bitmap, you should call the prior Bit-map’s ________ method to release its resources.
a. reuse
b. recycle-
c. release
d. discard
5.8.5 Methods clear, setDrawingColor, getDrawingColor, setLine-Width and getLineWidth
Q1. Call inherited View method ________ to indicate that the View needs to be re-drawn.
a. redraw
b. repaint
c. update
d. invalidate
5.8.6 Overridden View Method onDraw
Q1. When a View needs to be redrawn, its ________ method is called.
a. onUpdateRequred
b. onDraw
c. onPaint
d. None of the above
5.8.7 Overridden View Method onTouchEvent
Q1. Which of the following statements is false?
a. Motion-Event’s getActionMasked method returns an int representing the Mo-tionEvent type, which you can use with constants from class MotionEvent to de-termine how to handle each event.
b. Motion-Event’s getActionIndex method returns an integer index representing which finger caused the event. This index is the finger’s unique ID.
c. If the action is MotionEvent.ACTION_DOWN or Motion-Event.ACTION_POINTER_DOWN, the user touched the screen with a new finger. e. If the action is MotionEvent.ACTION_UP or MotionEvent.ACTION_POINTER_UP, the user removed a finger from the screen.
d. The first finger to touch the screen generates a MotionEvent.ACTION_DOWN event, and all other fingers generate Motion-Event.ACTION_POINTER_DOWN events.
5.8.8 touchStarted Method
Q1. If a Path already exists for the given ID, we call Path’s ________ method to clear any existing points so we can reuse the Path for a new stroke.
a. erase
b. clear
c. reset
d. reuse
5.8.9 touchMoved Method
Q1. Which of the following statements is false?
a. The system MotionEvent passed from onTouchEvent contains touch information for multiple moves on the screen if they occur at the same time.
b. MotionEvent method getPointerCount returns the number of touches the Mo-tion-Event describes.
c. MotionEvent-’s getX and getY methods to get the last coordinates for a drag event.
d. MotionEvents are not generated when the user holds a finger motionless on the screen.
5.8.10 touchEnded Method
Q1. Path’s ________ method clears the Path’s data.
a. restart
b. reset
c. reinitialize
d. clear
5.8.12 Method printImage
Q1. PrintHelper.SCALE_MODE_FIT indicates that ________.
a. the PrintHelper dialog should be scalled to fit on the screen
b. the image should be scaled to fit in the PrintHelper dialog
c. the image should fit within the printable area of the paper
d. None of the above
5.9.1 Overridden DialogFragment Method onCreateDialog
Q1. SeekBar’s ________ method positions the SeekBar’s thumb.
a. setPosition
b. setProgress
c. setValue
d. setThumb
5.9.3 Overridden Fragment Lifecycle Methods onAttach and onDetach
Q1. When a Fragment is removed from a parent Activity, method ________ is called.
a. onDestruct
b. onRemove
c. onDisconnect
d. onDetach
5.9.4 Anonymous Inner Class That Responds to the Events of the Alpha, Red, Green and Blue SeekBars
Q1. Method ________ is called when the position of a SeekBar’s thumb changes.
a. onSeekBarChanged
b. onThumbPositionChanged
c. onValueChanged
d. onProgressChanged
Leave a reply