0 arguments
PendingIntent
, 130
requestCode
, 130
using with communication, 130
: (colon), using with binder services, 134
action bar
action views, 204
documentation, 208
explained, 200
showing, 204
action views, using, 207
ActionBar.TabListener
, implementing, 207
ActionBarToggleDrawer
, setting as listener, 221
ActionBarToggleDrawer
arguments
Activity
, 220
CloseDrawerContentDescription
, 220
DrawerImageResource
, 220
DrawerLayout
, 220
OpenDrawerContentDescription
, 220
activities
basics, 26
vs. fragments, 192
methods, 32
NewActivity
class, 27
onResume
method, 32
onStart
method, 32
public void onResume()
, 34
public void onStart()
, 34
registering for events, 39
running, 34
saving primitives, 36
trying out, 31
Activity
class
controlling single screens, 25
getting back to main thread, 88
activity declaration, adding, 26
Adapter
class
explained, 104
getCount()
, 114
getItem()
, 114
getItemId()
, 114
interaction with ListView
, 119–121
ADB (Android Debug Bridge), restarting, 21
ADT Bundle. See Eclipse (ADT Bundle)
AIDL (Android Interface Definition Language), 133–134
Android Debug Bridge (ADB), restarting, 21
R.java
file, 63
types, 14
view pager, 212
Android SDK
accessing, 121
Android Studio
creating key in, 231
creating projects, 14
exporting release build, 229
features, 4
installing, 6
keystore file, 230
updating Android SDK, 7
virtual device emulator, 9
Android versions
downloading, 8
handling older code, 151
SharedPreferences
, 151
AndroidManifest.xml
file, 238
android:name
, 45
ANR (App Not Responding) crash, 85–86
API key, using with maps, 185–187
API levels, watching, 153
APK, producing final version of, 228–231
AppCompat library, setting up, 200–203
AppCompat project
adding as library project, 202
importing, 201
Application
class
customizing, 46
default declaration, 45
applications
checking, 99
ArrayAdapter
creating, 108
populating, 108
AsyncTask
abstract class
best practices, 93
generic type arguments, 91
ImageDownloader
, 90
onPostExecute
method, 89, 92–93
progress updates, 92
starting, 93
audio. See also sounds
playing in music service, 169–174
auto image uploading, 126
AVD (Android Virtual Device) Manager, 9–12
background color
changing for list view, 117
backing up keystore file, 231
binary format, packed, 63
binder interfaces, using with services, 125
binder services. See also communication
: (colon), 134
AIDL (Android Interface Definition Language), 133–134
IMusicService
, 135
marshaling process, 134
requirements, 133
class, 99
build files, adding signing keys to, 244–245
build types, using with Gradle files, 239–241
build variants, using with Gradle, 243–244
BuildConfig
, adding values to, 241
builds, submitting, 232
buildscript
, using with Gradle files, 237
Build.VERSION_CODE.GINGERBREAD
, 152
Build.VERSION.SDK_INT
, 152–153
buttons
layout folders example, 142–143
cache folder, using with IntentService
, 95–96
CameraUpdates
, using with maps, 187–188
checking applications, 99
click events, reacting to, 108–109
click listener, registering, 57
code, handling in older versions, 151
colon (:), using with binder services, 134
command line
directories for installation, 5–6
using in Eclipse, 17
communication. See also binder services; intent-based communication; services
binder interfaces, 125
intent broadcasts, 125
console statistics, seeing, 232–233
ContentProvider
, using in communication, 128–129
crash reports, watching and fixing, 232
cursor loader, using for music playback, 166
custom views. See also views
class declaration, 59
extending, 59
customizing applications, 45–46
data. See also loading data
creating for main menu, 104–105
data retention methods
onRetainNonConfigurationInstance
, 35–36
onSaveInstanceState
, 35
debugging. See also troubleshooting
layout issues, 149
preventing, 226
DemoListFragment
, 196
development environments
Android Studio, 4
Eclipse (ADT Bundle), 4
devices. See also working devices
unknown sources, 13
USB debugging, 13
dialogs, loading, 92
dip
or dp
(device-independent pixels), 53, 67
drawable folders, contents, 62–63, 65–66
DummyFragment
, using with getPageTitle
, 217
AppCompat library, 201
creating key in, 231
creating projects, 14
creating projects from command line, 17
exporting release build, 229
features, 4
installing, 5
keystore file, 230
updating Android SDK, 7
virtual device emulator, 9
emulator. See virtual device emulator
exceptions, handling, 113
release build in Android Studio, 229
release build in Eclipse, 229
files
AndroidManifest.xml
, 24
manifest, 24
saving to SD cards, 96
FragmentActivity
class
finding, 196
using with maps, 184
FragmentManager
, using, 198
FragmentPagerAdapter
explained, 212
getCount
method, 215
Locale.getDefault()
function, 217
overriding getPageTitle
, 216–217
fragments
vs. activities, 192
backward compatibility, 198–200
checking for, 197
compatibility library, 199–200
ContentFragment
class, 194
DemoListFragment
, 196
explained, 192
Gradle file, 198
onCreate
, 192
onCreateView
, 192
onDestroy
, 193
onDestroyView
, 193
onDetach
, 193
onPause
, 192
onResume
, 192
onStart
, 192
onStop
, 192
single text view, 195
startup lifecycle, 192
swapping for navigation drawer, 222
FragmentStatePagerAdapter
, 212
getCount
method
using with Adapter
class, 114
using with FragmentPagerAdapter
, 215
getExternalStorageDirectory
, 96
getItem()
method
using with Adapter
class, 114
getItemId()
, using with Adapter
class, 114
getLastKnownLocation
, 180
getPageTitle
function
DummyFragment
, 217
getView()
, using with Adapter
class, 114, 117
Google MapFragment
. See MapFragment
component
Google Maps API key
Google Play console statistics, 233
Gradle build file, using with maps, 182–183
Gradle files
Android versions, 238
AndroidManifest.xml
file, 238
AppCompat library, 200
backward compatibility, 198
buildscript
, 237
buildToolsVersion
, 238
compileSdkVersion
, 238
compiling JAR files, 239
example, 236
minSdkVersion
, 238
plugin: 'android,'
237
repositories
, 237
targetSdkVersion
, 238
values for BuildConfig
, 241
Gradle Plugin User Guide, accessing, 245
Gradle Wrapper (gradlew
), using, 245
gray background, adding, 79–80
handling exceptions, 113
height and width, determining for views, 51, 53
@id/.
, referencing for layouts, 77
IDE XML editor, using, 28
IDEs (integrated development environments)
Android Studio, 4
Eclipse (ADT Bundle), 4
image fetcher, implementing, 96–97
images
downloading and displaying, 84–85
fetching with IntentService
, 95–99
importing AppCompat project, 201
IMusicService
, extending, 135
<include>
tag, using with layout folders, 144–147
installation statistics, seeing, 232–233
installing
Android Studio, 6
Eclipse (ADT Bundle), 5
intent broadcasts, using with services, 125
intent-based communication. See also communication
0 arguments, 130
auto image uploading, 126
declaring services, 126
extending services, 127
overview, 126
PendingIntent
, 130
registering content observer, 129
intents
BroadcastReceiver
instance, 39–43
creating receivers, 40
explained, 37
getting, 32
receiving, 37
reviewing, 44
stopping listening, 41
IntentService
BroadcastReceiver
class, 99
cache folder for images, 95–96
rendering download, 98
JAR files, compiling, 239
Java
MATCH_PARENT
definition, 53
text view, 52
WRAP_CONTENT
definition, 53
Java vs. XML layouts, 55
key
creating in Android Studio, 231
creating in Eclipse, 231
keystore file
backing up, 231
creating in Android Studio, 230
creating in Eclipse, 230
using with signing key, 245
landscape folder, using, 144
landscape layout, 72
layout folders
adding suffixes to, 148
landscape folder, 144
<merge>
tag, 147
MVC (Model-View-Controller), 65
using, 144
layout issues, debugging, 149
layout management. See also picture viewer
for ListActivity
, 106
LinearLayout
button size, 74
match_parent
definition, 73
pixels, 74
specifying dimension, 107
width
setting, 73
Linux
installing Android Studio, 6
installing Eclipse (ADT Bundle), 5
list view
changing background color, 117
exceptions, 113
ListActivity
. See also menu list item
behavior, 109
declaring layout for, 106
ListView
class
explained, 104
interaction with Adapter
, 119–121
loading data. See also data
AsyncTask
abstract class, 89–93
locations. See also maps
getLastKnownLocation
, 180
getting for devices, 178
onLocationChanged
method, 180
permissions, 178
requestLocationUpdates
method, 179–180
logging, disabling prior to shipping, 230
ArrayAdapter
, 108
example, 109
reacting to click events, 108–109
ANR (App Not Responding) crash, 85–86
AsyncTask
abstract task, 89–93
best practices, 86
considering for services, 125
getting back to, 88
Loader
class, 100
verifying, 86
manifest files
AndroidManifest.xml
, 24
android:name
, 45
for maps, 183
map view
adding to manifest, 183
described, 181
modifying, 184
maps. See also locations
adding to manifest, 183
adjusting activity, 184
API key, 185
FragmentActivity
, 184
SDK manager options, 181
MarkerOptions
, using with maps, 187–188
marshaling process, explained, 134
match_parent
definition, 67
media. See also movies
OnDestroy
method, 161
onErrorListener
, 161
media players, cleanup, 174
MediaPlayer
states
Idle
, 162
Initialized
, 162
Playing
, 162
Prepared
, 162
MediaScanner
, using, 159
menu. See main menu
menu items
menu list item, creating, 107. See also ListActivity
<merge>
tag, using with layout folders, 147
messages, sending toasts, 41
movie playback process, 156
movies. See also media
adding VideoView
, 156
getting media to play, 157–159
passing URIs to video view, 159
setting up VideoView
, 157
music
binding to music service, 165
cursor loader, 166
finding recent tracks, 165–167
Idle
state, 162
Initialized
state, 162
longer-running, 164
MediaPlayer
and state, 162
playing sound effects, 163
Playing
state, 162
Prepared
state, 162
music playback
listening for intents, 167–169
process, 164
music service, playing audio in, 169–174
music software
audio focus, 174
headphone controls, 174
missing SD cards, 175
phone calls, 174
MVC (Model-View-Controller), 65
navigation, view pager, 212
navigation drawer
ActionBarDrawerToggle
, 220
ActionBarToggleDrawer
, 220
demo, 218
explained, 217
onItemClickListener
, 219
setContentView
, 219
setDisplayHomeAsUpEnabled
, 219–220
standard icon, 218
swapping fragments, 222
visible shadow, 219
XML, 221
NewActivity
class, creating, 27
notification, using in communication, 130–131
onBlind
, using with services, 124
onClickListener
, setting, 56–58
onCompletionListener
, calling for audio, 173–174
onCreate
method
using with fragments, 192
using with services, 124
onCreateView
, using with fragments, 192
onDestroy
method
using with fragments, 193
using with media, 161
using with services, 125
onDestroyView
, using with fragments, 193
onDetach
, using with fragments, 193
onErrorListener
, using with media, 161
onItemClickListener
, using with navigation drawer, 219
onLocationChanged
method, 180
onPause
method
using with fragments, 192
onResume
method
calling order, 32
using with fragments, 192
onRetainNonConfigurationInstance
method, 35–36
onSaveInstanceState
method, 35
onStart
method
invoking, 32
using with fragments, 192
onStartCommand
, using with services, 124
onStop
method
using with fragments, 192
OS X
installing Android Studio, 6
installing Eclipse (ADT Bundle), 5
packaging and signing, 228–231
packed binary format, 63
padding
declaration, 78
page change listener, creating, 214
PendingIntent
, flags associated with, 130
physical devices, working with, 12–13
picture viewer, 67. See also layout management
play
, calling for audio, 172–173
playing
sound effects, 163
plugin: 'android,'
using with Gradle, 237
Prev button, declaring, 78
primitives, saving, 36
product flavors, using with Gradle files, 242–243
project type, selecting, 14
projects
R.java
file, 63
view pager, 212
public void
onResume()
, 34
onStart()
, 34
RelativeLayout
nesting in, 80
padding
declaration, 78
Prev button, 78
referencing @id/.
, 77
release build, exporting, 229
repositories
, using with Gradle, 237
requestLocationUpdates
method, 179–180
res
folder
drawable folders, 62–63, 65–66
layout folders, 62, 64–65, 142–147
naming conventions, 63
resources, finding, 54
R.java
file, 63
saving
files to SD cards, 96
primitives, 36
screen layout, creating, 28–29
screens, controlling, 25
SD cards, saving files to, 96
SDK Manager, opening, 7
SDK methods, version checking, 152
SDK value, setting minimum, 228
SDK version number, 150
services. See also communication
explained, 124
keeping running, 125
lifecycles, 124
main thread, 125
onBlind
, 124
onCreate
, 124
onDestroy
method, 125
onStartCommand
, 124
startForeground
method, 125
setContentView
, using with navigation drawer, 219
setDataSource
, using with audio, 169–174
setDisplayHomeAsUpEnabled
, using with navigation drawer, 219–220
SharedPreferences
, commit
method, 151
signed build, exporting, 228–231
signing key, adding to build files, 244–245
sound effects, playing, 163
sounds, playing, 162–163. See also audio
sp
(scaled pixel), 53
startForeground
method, using with services, 125
StrictMode.enableDefaults()
, 99
tablets
building layouts for, 198
rendering on, 198
text editor, using, 28
text view, customizing, 59
thread. See main thread
toast, explained, 41
tracks, finding for music, 165–167
troubleshooting emulator, 21. See also debugging
UI (user interface)
finding resources, 54
XML vs. Java layouts, 55
unknown sources, allowing, 13
updating
applications frequently, 232–233
URIs, passing to video view, 159
USB debugging, enabling, 13
<uses>
tag, using with working devices, 150
values
folder
arrays, 64
colors, 64
contents, 62
dimensions, 64
strings, 64
styles, 64
version checking, 152
version codes
Build.VERSION_CODE.GINGERBREAD
, 152
Build.VERSION.SDK_INT
, 152–153
versioning, 227
video view, passing URIs to, 159
VideoView
adding for movies, 156
setting up for movies, 157
View
class, explained, 50
view pager
ActionBar
navigation mode, 214
creating project, 212
explained, 212
FragmentPagerAdapter
, 212, 215–216
FragmentStatePagerAdapter
, 212
page change listener, 214
SectionPagerAdapter
class, 214
XML, 215
ViewGroup
class
extending, 66
picture viewer, 67
views. See also custom views
anonymous inner class objects, 58
centering between objects, 79
defining in LinearLayout
, 70–75
dip
or dp
(device-independent pixels), 53
match_parent
definition, 53
MATCH_PARENT
definition, 53
px
(pixels), 53
retrieving, 54
sp
(scaled pixel), 53
using extended, 60
wrap_content
definition, 53
WRAP_CONTENT
definition, 53
Snapshot option, 12
troubleshooting, 21
Use Host GPU option, 12
visibility, changing for views, 55–58
width and height, determining for views, 51, 53
Windows
installing Android Studio, 6
installing Eclipse (ADT Bundle), 5
working devices. See also devices
SDK version number, 150
<uses>
tag, 150
XML
editing, 28
vs. Java layouts, 55
match_parent
definition, 53
navigation drawer, 221
view pager, 215
wrap_content
definition, 53
XML files
packed binary format, 63
referencing resources, 63
XML terms
dip
or dp
(device-independent pixels), 67
match_parent
definition, 67
px
(pixels), 67