Android How to Program Chapter 06 test bank
Download file with the answers
Android How to Program Chapter 06
1 file(s) 88.34 KB
If you are not a member register here to download this file
Chapter 6 Cannon Game App
6.3.1 Using the Resource Folder res/raw
Q1. Media files (such as the sounds we used in the Cannon Game app), are placed in the app’s resource folder ________.
a. res/media
b. res/sounds
c. res/raw
d. res/multimedia
6.3.2 Activity and Fragment Lifecycle Methods
Q1. Which of the following statements is false?
a. When an Activity is shut down, its onDestroy method is called, which in turn calls the onDestroy methods of all the Fragments hosted by the Activity.
b. We used the onDestroy method in the MainActivityFragment to release the CannonView’s sound resources.
c. Method onDestroy is guaranteed to be called, so it can be used to release re-sources and to save critical data.
d. The Android documentation recommends that you save data in methods onPause or onSaveInstanceState.
6.3.3 Overriding View Method onTouchEvent
Q1. To process simple touch events in an app, override View method on-TouchEvent, then use constants from class ________ (package android.view) to test which type of event occurred and process it accordingly.
a. Event
b. MotionEvent
c. Motion
d. View
6.3.4 Adding Sound with SoundPool and AudioManager
Q1. An app’s sound effects are managed with a(n) ________ (package an-droid.media), which can be used to load, play and unload sounds.
a. Effects
b. SoundPool
c. EffectsPool
d. SoundManager
Q2. Sounds are played using one of Android’s audio- ________ for alarms, music, notifications, phone rings, system sounds, phone calls and more.
a. streams
b. players
c. tools
d. None of the above
Q3. The Android documentation recommends that games use the ________ to play sounds, because that stream’s volume can be controlled via the device’s volume buttons.
a. phone audio stream
b. alarm audio stream
c. notifications audio stream
d. music audio stream
Q4. Which of the following statements is false?
a. You configure and create a SoundPool object using a SoundPool.Builder ob-ject.
b. You use an AudioAttributes.Builder object to create an AudioAttributes object that will be associated with the SoundPool.
c. AudioAttributes’s setGameAudio method is used to designate the audio as game audio.
d. Activity’s setVolumeControlStream method allows the game’s volume to be controlled with the device’s volume buttons.
6.3.5 Frame-by-Frame Animation with Threads, SurfaceView and SurfaceHolder
Q1. All updates to an app’s user interface must be performed in the GUI thread of execution, because GUI components are not ________.
a. thread ready
b. thread safe
c. thread capable
d. None of the above
Q2. Games, often require complex logic that should be performed in separate threads of execution, and those threads often need to draw to the screen. For such cases, Android provides class ________—a subclass of View that provides a dedi-cated drawing area in which other threads can display graphics on the screen in a thread-safe manner.
a. GameView
b. ThreadView
c. ThreadSafeView
d. SurfaceView
Q3. Each SurfaceView subclass should implement the interface ________, which contains methods that are called when the SurfaceView is created, changed (e.g., its size or orientation changes) or destroyed.
a. SurfaceHolder.Callback
b. SurfaceHolderCallback
c. Surface.Callback
d. SurfaceCallback
6.3.6 Simple Collision Detection
Q1. Game-development frameworks typically provide sophisticated ________ colli-sion-detection capabilities.
a. pixel-based
b. perfect
c. pixel-perfect
d. None of the above
6.3.7 Immersive Mode
Q1. Which of the next three statements is false?
a. Full-screen immersive mode enables an app to take advantage of the entire screen.
b. When an app is in immersive mode, the user can swipe down from the top of the screen to display the system bars temporarily.
c. If the user does not interact with the system bars, they disappear after a few sec-onds.
d. All of the above are true.
6.4.1 Creating the Project
Q1. Which of the next three statements is false?
a. You can add a Fragment and its layout manually.
b. You can design an app for only landscape orientation.
c. To set the screen orientation to landscape, set android:-orientation to land-scape.
d. Each of the above is true.
6.4.2 Adjusting the Theme to Remove the App Title and App Bar
Q1. Game developers often use full-screen themes, such as
Theme.Material.Light.NoActionBar.Fullscreen
that display only the bottom system bar, which in landscape orientation appears at the screen’s ________.
a. top
b. bottom
c. left edge
d. right edge.
6.4.6 Adding Class MainActivityFragment
Q1. A Frame-Layout is designed to display one View, but can also be used to ________ views.
a. stack
b. nest
c. position
d. layer
6.7 MainActivityFragment Subclass of Fragment
Q1. There are seven sound streams identified by AudioManager constants. The mu-sic stream ________ is recommended for sound in games, because this stream’s volume can be controlled via the device’s buttons.
a. AudioManager.STREAM
b. AudioManager.MUSIC
c. AudioManager.STREAM_MUSIC
d. AudioManager.SYMPHONY
6.12.4 Method draw
Q1. Canvas’s ________ method draws a circle.
a. drawOval
b. drawEllipse
c. drawCircle
d. None of the above
6.13.3 Constructor
Q1. When a View is inflated, its constructor is called with a Context and a(n) ________ as arguments.
a. SetOfAttributes
b. Attributes
c. OptionsSet
d. AttributeSet
Q2. Pass ________ to an AudioAttributes.Builder object’s setUsage method to indicate that the audio is being used as game audio.
a. AudioAttribute.USAGE_GAME
b. AudioAttribute.GAME
c. AudioAttribute.GAME_USAGE
d. None of the above
Q3. Which of the following statements is false?
a. More complex games might play many sounds at the same time. Sound-Pool.Builder’s setMaxStreams method takes an argument that represents the maximum number of simultaneous sound streams that can play at once.
b. A SparseIntArray maps integer keys to integer values. HashMap<Integer, In-teger> is similar to—but more efficient than—a SparseIntArray for small num-bers of key–value pairs.
c. Each sound ID can be used to play a sound (and later to return its resources to the system).
d. SoundPool method load receives three arguments—the application’s Context, a re-source ID representing the sound file to load and the sound’s priority.
6.13.4 Overriding View Method onSizeChanged
Q1. Class View’s onSizeChanged method is called whenever the View’s size chang-es, including when the View is first added to the View hierarchy as the layout is in-flated. The method receives the View’s new width and height and its old width and height. The first time this method is called, the old width and height are ________ and ________.
a. 0, 0
b. 0, 1
c. 1, 0
d. 1, 1
6.13.5 Methods getScreenWidth, getScreenHeight, and playSound
Q1. Methods getScreenWidth and getScreenHeight return the width and height of the screen, which are updated in the ________ method.
a. onOrientationChanged
b. onSizeChanged
c. onConfigurationChanged
d. None of the above
6.13.7 Method updatePositions
Q1. You can terminate a Thread by calling its setRunning method with the argu-ment ________.
a. terminate
b. true
c. kill
d. false
6.13.9 Method showGameOverDialog
Q1. A dialog must be displayed from the GUI thread. You call Activity method ________ to specify a Runnable that should execute in the GUI thread.
a. runOnUiThread
b. executeOnUIThread
c. uiThread
d. None of the above
6.13.10 Method drawGameElements
Q1. You can call Canvas’s drawRect method to clear the Canvas. The method re-ceives the rectangle’s upper-left x-y coordinates, width and height, and the ________ object that specifies the drawing characteristics.
a. Draw
b. PaintSettings
c. Paint
d. DrawSettings
6.13.12 Methods stopGame and releaseResources
Q1. Class SoundPool’s ________ method gives the resources associated with a SoundPool back to the system.
a. reset
b. release
c. reinitialize
d. restore
6.13.13 Implementing the SurfaceHolder.Callback Methods
Q1. Method ________ of interface SurfaceHolder.Callback is called when the SurfaceView’s size or orientation changes, and would typically be used to redisplay graphics based on those changes.
a. surfaceSizeChanged
b. surfaceOrientationChanged
c. onSizeChanged
d. surfaceChanged
Q2. Method surfaceCreated is called when the SurfaceView is created—e.g., ________.
a. when the app first loads
b. when the app resumes from the background
c. Both of the above
d. Neither of the above
6.13.14 Overriding View Method onTouchEvent
Q1. View method onTouchEvent determines when the user touches the screen. The MotionEvent parameter contains information about the event that occurred. If the user touched the screen, the parameter’s value is ________.
a. MotionEvent.ACTION_DOWN
b. MotionEvent.ACTION_TOUCH
c. MotionEvent.ACTION_TAP
d. MotionEvent.ACTION_DRAG
6.13.15 CannonThread: Using a Thread to Create a Game Loop
Q1. To obtain the Canvas for drawing on the SurfaceView, call SurfaceHolder method ________.
a. getCanvas
b. createCanvas
c. newCanvas
d. lockCanvas
Q2. Only one thread at a time can draw to a SurfaceView. To ensure this, you must first lock the SurfaceHolder by ________.
a. calling lockSurfaceHolder
b. specifying it as the expression in the parentheses of a synchronized block.
c. calling getSurfaceHolderLock
d. None of the above
6.13.16 Methods hideSystemBars and showSystemBars
Q1. Immersive mode is available in Android 4.4 (API level 19) and higher. You can check at runtime whether the device’s version is at least Android 4.4 (API level 19) by checking whether ________ is at least Build.VERSION_CODES_KITKAT.
a. Build.VERSION_SDK
b. Build.VERSION_SDK_INT
c. Build.VERSION_INT
d. Build.SDK_INT
Leave a reply