Android How to Program Chapter 10 Solution Manual
Download file with the answers
Android How to Program Chapter 10 Solution Manual
1 file(s) 269.46 KB
If you are not a member register here to download this file
10 Address Book App
Obj e c t i v e s
In this chapter you’ll:
■ Extend ListActivity to
create an Activity that
consists of a ListView by
default.
■ Create multiple Activity
subclasses to represent the
app’s tasks and use explicit
Intents to launch them.
■ Create and open SQLite
databases using a
SQLiteOpenHelper, and
insert, delete and query data
in a SQLite database using a
SQLiteDatabase object
■ Use a
SimpleCursorAdapter to
bind database query results
to a ListView’s items.
■ Use a Cursor to manipulate
database query results.
■ Use multithreading to
perform database operations
outside the GUI thread and
maintain application
responsiveness.
■ Define styles containing
common GUI attributes and
values, then apply them to
multiple GUI components.
■ Create XML menu resources
and inflate them with a
MenuInflater.
2 Chapter 10 Address Book App
Self-Review Exercises
10.1 Fill in the blanks in each of the following statements:
a) Activity method is called when the Activity is no longer visible to the
user—typically because another Activity has started or returned to the foreground.
b) You obtain the MenuInflater by calling Activity’s method.
10.2 State whether each of the following is true or false. If false, explain why.
a) (True/False) The AndroidManifest.xml file describes an app’s components.
b) (True/False) SQLite (www.sqlite.org) is the world’s most widely deployed database engine.
c) (True/False) It’s good practice to perform long running operations or operations that
block execution until they complete (e.g., file and database access) in the GUI thread.
d) (True/False) Each menu resource XML file contains a root menu element with nested item
elements that represent each MenuItem.
e) (True/False) SimpleCursorAdapter is a subclass of CursorAdapter that’s designed to
simplify mapping Cursor columns directly to TextViews or ImagesViews defined in
your XML layouts.
f) (True/False) When an Activity is stopped, it will call deactivate on any Cursors it’s
currently managing. When the Activity resumes, it will call requery on its Cursors.
When the Activity is destroyed, it will automatically call close to release all resources
held by any managed Cursors.
g) (True/False) It’s considered good practice to ensure that Cursor method moveToFirst
returns false before attempting to get data from the Cursor.
true before attempting to get data from the Cursor.
h) (True/False) It’s good practice to release resources like database connections when they
are not being used so that other activities can use the resources.
Exercises
10.3 Fill in the blanks in each of the following statements:
a) SQLite database query results are managed via a (package
android.database).
b) When we need a database operation’s results in the GUI thread, we’ll use an
(package android.os) to perform the operation in one thread and receive the results in
the GUI thread.
Exercises 3
c) Method is called each time an Activity returns to the foreground, including
when the Activity is first created.
d) Activity method getIntent returns the Intent that launched the Activity. We use
that to call Intent method , which returns a Bundle that contains any key–
value pairs that were added to the Intent as extras.
e) The Cursor returned by method query contains all the table rows that match the method’s
arguments—the so-called .
10.4 State whether each of the following is true or false. If false, explain why.
a) (True/False) Each Activity must be described in the app’s manifest.
ANS: True.
b) (True/False) Resource files that define menus are placed in the app’s res/menu folder
(which you must create) and are added to the project like other resource files, but in the
New Android XML File dialog you select Menu as the resource type.
c) (True/False) A key benefit of using an SyncTask is that it handles the details of creating
threads and executing its methods on the appropriate threads for you, so that you do
not have to interact with the threading mechanism directly.
d) (True/False) A deactivated Cursor consumes more resources than an active one, so it’s
good practice to align your Cursor’s lifecycle with its parent Activity if the Cursor is
not shared among multiple Activity objects.
e) (True/False) Allowing your Activity to manage the Cursor’s lifecycle also ensures that
the Cursor will be closed when it’s no longer needed.
Leave a reply