Android How To Program 3rd Edition Deitel Test Bank Download

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Android How to Program 3rd Edition

Deitel 0134444302 9780134444307


Download solution manual at:
https://testbankpack.com/p/solution-manual-for-android-
how-to-program-3rd-edition-deitel-0134444302-
9780134444307/

Download full test bank at :

https://testbankpack.com/p/test-bank-for-android-how-to-
program-3rd-edition-deitel-0134444302-9780134444307/

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 per-
missions 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.
Answer: c. requests each permission individually, only when the permission is re-
quired to perform a given task for the first time

© Copyright 2017 by Pearson Education, Inc. All Rights Reserved.


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 integers
in the range 0–255.
a. transparency
b. translucency
c. alpha
d. None of the above.
Answer: c. alpha

5.3 Technologies Overview


No questions.

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 cor-
responding 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.
Answer: b. There are six Activity lifecycle methods that have corresponding
Fragment lifecycle methods—onCreate, onLoad, onResume, onPause, onStop and
onDestroy. Actually, there are six Activity lifecycle methods that have corre-
sponding Fragment lifecycle methods—onCreate, onStart, onResume, onPause,
onStop and onDestroy.

Q2. Which of the following statements is false?


a. When an Activity hosts Fragments and the Activity is resumed, all of its Frag-
ments’ 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.
Answer: d. When an app is paused, it should ensure that listeners for sensor
events are still active. Actually, when an app is paused, it should remove listeners
for sensor events so these events are not delivered to the app when it’s not on the
screen. This saves battery.
© Copyright 2017 by Pearson Education, Inc. All Rights Reserved.
5.3.2 Custom Views
No questions.

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.
Answer: c. accelerometer

5.3.4 Custom DialogFragments


No questions.

5.3.5 Drawing with Canvas, Paint and Bitmap


Q1. Each drawing method in class Canvas uses an object of class ________ (package
android.graphics) to specify drawing characteristics, including color, line thick-
ness, font size and more.
a. Draw
b. Characteristics
c. Settings
d. Paint
Answer: 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
Answer: c. Path

Q2. In addition to standard touch-event handling, Android 6.0 provides enhanced sup-
port 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
Answer: b. Bluetooth

© Copyright 2017 by Pearson Education, Inc. All Rights Reserved.


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
Answer: a. Content-Resolver

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 print-
ing a Bitmap.
a. Printer
b. PrinterUI
c. PrintHelper
d. None of the above
Answer: c. PrintHelper

5.3.9 New Android 6.0 (Marshmallow) Permissions Model


Q1. Which of the following statements is false?
a. Android requires the permission android.permission.WRITE_EXTERNAL_PER-
MISSION before an app can write to external storage.
b. Before Android 6.0, a user was required at start time to grant in advance all permis-
sions 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 permis-
sions. Instead, the user is asked to grant a permission only the first time the correspond-
ing feature is used.
d. Once the user grants a permission, the app has that permission until the app is rein-
stalled or the user changes the app’s permissions via the Android Settings app.
Answer: b. Before Android 6.0, a user was required at start time to grant in ad-
vance all permissions that an app would ever need—this caused many people not
to install certain apps. b. Before Android 6.0, a user was required at installation
time to grant in advance all permissions that an app would ever need—this caused
many people not to install certain apps.

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 in-
cluding in the build process any libraries used by the app.
a. Buck
b. Maven
c. Bazel
d. Gradle
© Copyright 2017 by Pearson Education, Inc. All Rights Reserved.
Answer: d. Gradle build

5.4 Creating the Project and Resources


No questions.

5.4.1 Creating the Project


No questions.

5.4.2 Gradle: Adding a Support Library to the Project


No questions.

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
Answer: b. use all capital letters (e.g., CANCEL or SET COLOR) for languages that
support them

5.4.4 Importing the Material Design Icons for the App’s Menu
Items
No questions.

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
Answer: a. showAsAction

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 permissions
it uses in ________.
a. class MainActivity
b. strings.xml
c. permissions.xml
d. AndroidManifest.xml
Answer: d. AndroidManifest.xml
© Copyright 2017 by Pearson Education, Inc. All Rights Reserved.
5.5 Building the App’s GUI
No questions.

5.5.1 content_main.xml Layout for MainActivity


No questions.

5.5.2 fragment_main.xml Layout for MainActivityFragment


No questions.

5.5.3 fragment_color.xml Layout for ColorDialogFragment


No questions.

5.5.4 fragment_line_width.xml Layout for


LineWidthDialogFragment
No questions.

5.5.5 Adding Class EraseImageDialogFragment


No questions.

5.6 MainActivity Class


No questions.

5.7 MainActivityFragment Class


No questions.

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
Answer: c. float

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
© Copyright 2017 by Pearson Education, Inc. All Rights Reserved.
Answer: a. setHasOptionsMenu

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
Answer: 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
Answer: b. unregisterListener

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
Answer: c. onSensorChanged

5.7.6 Method confirmErase


No questions.

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
© Copyright 2017 by Pearson Education, Inc. All Rights Reserved.
Answer: c. onOptionsItemSelected

5.7.8 Method saveImage


Q1. If an app does not have a needed permission (such as android.permis-
sion.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
Answer: d. shouldShowRequestPermissionRationale

5.7.9 Overridden Method onRequestPermissionsResult


No questions.

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 loosely
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.
Ans: a. When an app’s Fragments interact with one another directly, we call this
a loosely coupled approach. Actually this kind of direct interaction is a tightly
coupled approach.

5.8 DoodleView Class


No questions.

5.8.1 package Statement and import Statements


No questions.

5.8.2 static and Instance Variables


No questions.

5.8.3 Constructor
Q1. Passing true to Paint’s ________ method enables smoothing the edges of the
lines.
a. setSmoothing
b. setHigherResolution

© Copyright 2017 by Pearson Education, Inc. All Rights Reserved.


c. setAntiAlias
d. None of the above
Answer: c. setAntiAlias

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
Answer: b. recycle-

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
Answer: 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
Answer: b. onDraw

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 deter-
mine 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 MotionEvent.AC-
TION_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 re-
moved a finger from the screen.
© Copyright 2017 by Pearson Education, Inc. All Rights Reserved.
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.
Answer: b. Motion-Event’s getActionIndex method returns an integer index
representing which finger caused the event. This index is the finger’s unique ID.
Actually, this index is not the finger’s unique ID—it’s simply the index at which
that finger’s information is located in this MotionEvent object.

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
Answer: c. reset

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 Motion-
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.
Answer: d. MotionEvents are not generated when the user holds a finger motion-
less on the screen. Actually, many devices are sensitive enough to generate Mo-
tionEvents indicating small movements when the user is attempting to hold a fin-
ger 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
Answer: b. reset

5.8.11 Method saveImage


No questions.

5.8.12 Method printImage


Q1. PrintHelper.SCALE_MODE_FIT indicates that ________.
© Copyright 2017 by Pearson Education, Inc. All Rights Reserved.
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
Answer: c. the image should fit within the printable area of the paper

5.9 ColorDialogFragment Class


No questions.

5.9.1 Overridden DialogFragment Method onCreateDialog


Q1. SeekBar’s ________ method positions the SeekBar’s thumb.
a. setPosition
b. setProgress
c. setValue
d. setThumb
Answer: b. setProgress

5.9.2 Method getDoodleFragment


No questions.

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
Answer: 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
Answer: onProgressChanged

5.10 LineWidthDialogFragment Class


No questions.

© Copyright 2017 by Pearson Education, Inc. All Rights Reserved.


5.10.1 Method onCreateDialog
No questions.

5.10.2 Anonymous Inner Class That Responds to the Events of


the widthSeekBar

5.11 EraseImageDialogFragment Class

5.12 EraseImageDialogFragment Class


No questions.

© Copyright 2017 by Pearson Education, Inc. All Rights Reserved.

You might also like