In Fall 2018 at
this course is
has the same format.
<activity>element in the app’s
AndroidManifest.xmlfile specifies which subclass of class
Activitywill be instantiated.
onCreatemethod of the activity object when the app is launched.
onCreateis one of the methods in one of the three pairs of Activity lifecycle methods. Don’t call them directly. For example, call
finishto trigger a call to
onDestroy. Permanent data should be saved in
onPause, not in
RelativeLayoutwhich contains a
TextView. The items inside a
RelativeLayoutcan have positioning attributes such as
FrameLayout.LayoutParams. A FrameLayout usually holds only one child. See exercise 12 in LinearLayout; exercise 1 in GridView; Sqlite.
ifstatements, and objects. Input and output are performed by dialog boxes that pop up and are dismissed.
Toaston the Android screen.
TextViewon the Android screen.
adb logcatcommand on your Mac or PC. Direct the standard output into a pipe or a file.
find, etc.) on your Android emulator or device.
This is the most important topic of the course.
View.OnClickListenercan be installed into a
Buttonor into any other type of
View.OnClickListenerhas a method named
onClick. Composition vs. inheritance.
View.OnKeyListenercan be installed into an
View.OnKeyListenerhas a method named
SeekBar.OnSeekBarChangeListenercan be installed into a
SeekBar.OnSeekBarChangeListenerhas a method named
DatePicker.OnDateChangedListenercan be installed into a
DatePicker.OnDateChangedListenerhas a method named
If you want the same interface each time you run the app,
create it with an
If the interface might be different during each run,
create it with executable Java code containing
statements and other conditionals.
activity_main.xmlfile of the Click Listener example.
Draw the graphics in a subclass of class
containing a constructor and an
View, and an object of that class.
Canvasargument passed to
Pathcontaining a series of points connected by straight lines:
lineTo. Needed because
Canvashas no methods for drawing triangles, pentagons, houses, etc.
The following pictures redraw themselves when you touch the screen.
method of class
View.OnTouchListenerand its method
onTouch. Uses the
Pathwe saw in the triangle in Japan. Erases itself when the activity’s configuration (e.g., orientation) changes; see Configuration Changes.
Make the graphics move under their own power, without having to be dragged with a finger. See Animation and Graphics.
Animationobject such as
TranslateAnimation(added in API 1) can smoothly change the position at which a
Viewis displayed, but it has no effect on the
Viewitself and its fields. This type of animation has been superseded by ViewPropertyAnimator, is applicable only to an object of class
Viewand only to certain of its properties: alpha, translate, scale, and rotate. See View Animation.
ViewPropertyAnimator(added in API 12) is the fastest and simplest way to smoothly change a field of a
Viewobject. This type of animation is applicable only to an object of class
Viewand only to certain of its properties: alpha, translate, scale, rotate, x, y, and z. See Animating with ViewPropertyAnimator.
Activityin this app uses two
ObjectAnimator(added in API 11) can smoothly change any field of any object, including objects that are not
Views and fields of any data type. Unlike an
ObjectAnimatoractually changes the object’s fields, not merely its appearance on the screen. See Animating with ObjectAnimator.
ObjectAnimatorto animate the top padding property of a
postto update the user interface in the main thread.
Implement an animation by having a separate
(instead of plain old
over and over to trigger calls to the
method of the
is touch-sensitive because we plugged a
The touch listener can store information about each touch into a
When the gesture detector feels it has received all the information
necessary to constitute a gesture,
it calls one of the methods of the
plugged into the gesture detector.
A data item is a number, string, image, etc.
We can display one or more data items in a
by calling the
methods of the
passed to the
method of the
for an example.
In this section,
we will display each data item in its own
takes a series of data items
and encases each one in a
The simplest example of an
which gets its data items from a Java array.
but does not actually display them on the screen.
To display the
we plug the
which is a big
that can display smaller
In other words, an
is an example of
In more other words,
is a subclass of class
Layouts with an Adapter.
Spinner(dropdown menu). The
Adapterwe plug into this
ListViewis another example of an
ArrayAdapterhere, so we’ll have to build our own implementation of interface
GridViewis another type of
AdapterView. We’ll have to make our own implementation of the
SimpleCursorAdaptercan write an image into an
ImageViewas easily as it can write text into a
sqlite3command line shell.
Cursorcomes from a
CursorLoaderrunning under the control of the
Adapter; plug the
GridViewof real estate offers read from an SQLite database.
object to launch an
belonging to another app.
The main thread must never attempt a job that takes more than five seconds.
For longer jobs,
the main thread must create a worker thread.
But only the main thread can access the user interface.
for threads with
Handler. Examples: animation, time picker.
AsyncTask. See How to Avoid ANRs. Example.
MediaRecorderand save the file in the Music folder.
Activityplay music using a
MediaPlayer. The music starts playing from the beginning when the
Activityis destroyed and recreated by a change of orientation.
MediaPlayer, but now run by a Service instead of by the Activity. The music reliably keeps playing even after the
Serviceis executed by a separate thread.
MapViewusing the Google Maps Android API version 2.
Markerthere with a label and