Index

Numbers

0 arguments

PendingIntent, 130

requestCode, 130

using with communication, 130

Symbol

: (colon), using with binder services, 134

A

AbsoluteLayout, 6870

action bar

action views, 204

adding elements to, 204208

AppCompat library, 200203

documentation, 208

explained, 200

menu items, 204205

showing, 204

tabs, 204, 207208

view pager, 212213

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

creating screen layout, 2829

data retention methods, 3536

vs. fragments, 192

handling collisions, 4243

implementing, 2631

launching, 2931

lifecycles, 3233

methods, 32

NewActivity class, 27

onCreate method, 3233

onDestroy method, 32, 35

onPause method, 32, 34

onResume method, 32

onStart method, 32

onStop method, 32, 34

public void onCreate(), 3334

public void onResume(), 34

public void onStart(), 34

pushing button, 2930

registering for events, 39

running, 34

saving primitives, 36

trying out, 31

Activity class

controlling single screens, 25

extending, 2526

getting back to main thread, 88

activity declaration, adding, 26

Adapter class

customizing, 114116

explained, 104

getCount(), 114

getItem(), 114

getItemId(), 114

getView(), 114, 117

interaction with ListView, 119121

ADB (Android Debug Bridge), restarting, 21

ADT Bundle. See Eclipse (ADT Bundle)

AIDL (Android Interface Definition Language), 133134

Android Debug Bridge (ADB), restarting, 21

Android projects

creating, 1416

R.java file, 63

running, 1820

types, 14

view pager, 212

Android SDK

accessing, 121

updating, 78

Android Studio

AppCompat library, 200203

creating key in, 231

creating projects, 14

exporting release build, 229

features, 4

installing, 6

keystore file, 230

maps, 182183

running projects in, 1920

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, 8586

API key, using with maps, 185187

API levels, watching, 153

APK, producing final version of, 228231

AppCompat library, setting up, 200203

AppCompat project

adding as library project, 202

enabling, 202203

importing, 201

Application class

customizing, 46

default declaration, 45

applications

accessing, 4647

checking, 99

customizing, 4546

updating frequently, 232233

ArrayAdapter

creating, 108

populating, 108

AsyncTask abstract class

best practices, 93

doInBackground method, 89, 91

example, 8990

generic type arguments, 91

ImageDownloader, 90

onPostExecute method, 89, 9293

onPreExecute method, 89, 91

progress updates, 92

starting, 93

audio. See also sounds

calling play, 172173

onCompletionListener, 173174

playing in music service, 169174

setDataSource, 169174

auto image uploading, 126

AVD (Android Virtual Device) Manager, 912

B

background color

changing for list view, 117

gray, 7980

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), 133134

binder and AIDL stub, 135136

binding, 136137

communicating with, 136137

creating services, 134135

IMusicService, 135

marshaling process, 134

requirements, 133

BroadcastReceiver

class, 99

instance, 3943

build files, adding signing keys to, 244245

build types, using with Gradle files, 239241

build variants, using with Gradle, 243244

BuildConfig, adding values to, 241

builds, submitting, 232

buildscript, using with Gradle files, 237

Build.VERSION_CODE.GINGERBREAD, 152

Build.VERSION.SDK_INT, 152153

buttons

layout folders example, 142143

pushing, 2930

sizes in LinearLayout, 7475

C

cache folder, using with IntentService, 9596

CameraUpdates, using with maps, 187188

checking applications, 99

click events, reacting to, 108109

click listener, registering, 57

code, handling in older versions, 151

colon (:), using with binder services, 134

command line

directories for installation, 56

using in Eclipse, 17

communication. See also binder services; intent-based communication; services

binder interfaces, 125

intent broadcasts, 125

intent-based, 126133

console statistics, seeing, 232233

ContentProvider, using in communication, 128129

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, 4546

D

data. See also loading data

creating for main menu, 104105

moving, 4345

data retention methods

onRetainNonConfigurationInstance, 3536

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

working with, 1213

dialogs, loading, 92

dip or dp (device-independent pixels), 53, 67

drawable folders, contents, 6263, 6566

DummyFragment, using with getPageTitle, 217

E

Eclipse (ADT Bundle)

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

maps, 182183

running projects in, 1819

updating Android SDK, 7

virtual device emulator, 9

emulator. See virtual device emulator

exceptions, handling, 113

exporting

release build in Android Studio, 229

release build in Eclipse, 229

signed build, 228231

F

file storage, 9596

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

getItem method, 215216

Locale.getDefault() function, 217

overriding getPageTitle, 216217

fragments

vs. activities, 192

backward compatibility, 198200

checking for, 197

compatibility library, 199200

ContentFragment class, 194

creating, 193194

DemoListFragment, 196

explained, 192

Gradle file, 198

lifecycles, 192193

onCreate, 192

onCreateView, 192

onDestroy, 193

onDestroyView, 193

onDetach, 193

onPause, 192

onResume, 192

onStart, 192

onStop, 192

showing, 194198

single text view, 195

startup lifecycle, 192

swapping for navigation drawer, 222

FragmentStatePagerAdapter, 212

G

getCount method

using with Adapter class, 114

using with FragmentPagerAdapter, 215

getExternalStorageDirectory, 96

getItem() method

FragmentPagerAdapter, 215216

using with Adapter class, 114

getItemId(), using with Adapter class, 114

getLastKnownLocation, 180

getPageTitle function

DummyFragment, 217

overriding, 216217

getView(), using with Adapter class, 114, 117

Google MapFragment. See MapFragment component

Google Maps API key

signing up for, 185186

using, 185186

Google Play console statistics, 233

Gradle build file, using with maps, 182183

Gradle files

Android versions, 238

AndroidManifest.xml file, 238

AppCompat library, 200

backward compatibility, 198

build types, 239241

build variants, 243244

buildscript, 237

buildToolsVersion, 238

compileSdkVersion, 238

compiling JAR files, 239

example, 236

minSdkVersion, 238

plugin: 'android,' 237

product flavors, 242243

repositories, 237

signing and building, 244245

targetSdkVersion, 238

values for BuildConfig, 241

Gradle Plugin User Guide, accessing, 245

Gradle Wrapper (gradlew), using, 245

gray background, adding, 7980

H

handling exceptions, 113

height and width, determining for views, 51, 53

I

@id/., referencing for layouts, 77

IDE XML editor, using, 28

IDEs (integrated development environments)

Android Studio, 4

Eclipse (ADT Bundle), 4

image fetcher, implementing, 9697

ImageReceiver class, 9899

images

downloading and displaying, 8485

fetching with IntentService, 9599

importing AppCompat project, 201

IMusicService, extending, 135

<include> tag, using with layout folders, 144147

installation statistics, seeing, 232233

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

ContentProvider, 128129

declaring services, 126

extending services, 127

going to foreground, 129131

notification, 130131

overview, 126

PendingIntent, 130

registering content observer, 129

starting services, 127128

IntentFilter instance, 3943

intents

adding, 3839

Airplane mode, 4142

BroadcastReceiver instance, 3943

creating receivers, 40

explained, 37

getting, 32

IntentFilter instance, 3943

listening at runtime, 3943

listening for, 167169

manifest registration, 3738

receiving, 37

reviewing, 44

stopping listening, 41

IntentService

BroadcastReceiver class, 99

cache folder for images, 9596

cleanup, 9798

declaring services, 9495

fetching images, 9599

ImageReceiver class, 9899

notifyFinished method, 9798

rendering download, 98

J

JAR files, compiling, 239

Java

in Java, 5152

MATCH_PARENT definition, 53

text view, 52

views in, 5152

WRAP_CONTENT definition, 53

Java vs. XML layouts, 55

K

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

L

landscape folder, using, 144

landscape layout, 72

layout folders

adding suffixes to, 148

contents, 62, 6465

creating new layouts, 148149

<include> tag, 144147

landscape folder, 144

<merge> tag, 147

MVC (Model-View-Controller), 65

screen with buttons, 142143

using, 144

layout issues, debugging, 149

layout management. See also picture viewer

AbsoluteLayout, 6870

landscape mode, 72, 75

LinearLayout, 7075, 107

for ListActivity, 106

RelativeLayout, 7680

ViewGroup class, 6667

LinearLayout

button size, 74

defining views in, 7075

match_parent definition, 73

pixels, 74

specifying dimension, 107

using, 7375

width setting, 73

Linux

installing Android Studio, 6

installing Eclipse (ADT Bundle), 5

list items, types of, 120121

list view

building, 116119

changing background color, 117

custom adapter, 114116

exceptions, 113

ListActivity, 111112

main layout view, 110111

Reddit data, 112114

RedditAsyncTask, 112114

subreddits, 112114

TextViews, 117118

ListActivity. See also menu list item

behavior, 109

creating, 105, 111112

declaring layout for, 106

ListView class

explained, 104

interaction with Adapter, 119121

Loader class, 100, 168169

loading data. See also data

AsyncTask abstract class, 8993

IntentService, 94100

main thread, 8488

locations. See also maps

getLastKnownLocation, 180

getting for devices, 178

onLocationChanged method, 180

permissions, 178

receiving updates, 179180

requestLocationUpdates method, 179180

service suppliers, 178179

logging, disabling prior to shipping, 230

M

main menu

ArrayAdapter, 108

creating data, 104105

example, 109

ListActivity, 105106, 109

reacting to click events, 108109

main thread

ANR (App Not Responding) crash, 8586

AsyncTask abstract task, 8993

best practices, 86

considering for services, 125

getting back to, 88

getting off, 8788

IntentService, 9499

Loader class, 100

managing, 8485

verifying, 86

manifest files

AndroidManifest.xml, 24

android:name, 45

for maps, 183

manifest registration, 3738

map view

CameraUpdates, 187188

MarkerOptions, 187188

running, 187188

MapFragment component

adding to manifest, 183

creating, 184185

described, 181

getting, 181183

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, 187188

marshaling process, explained, 134

match_parent definition, 67

media. See also movies

loading data, 160161

OnDestroy method, 161

onErrorListener, 161

playing, 160161

media players, cleanup, 174

MediaPlayer states

Idle, 162

Initialized, 162

Playing, 162

Prepared, 162

MediaScanner, using, 159

menu. See main menu

menu items

adding to action bar, 205206

reacting to clicks, 206208

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, 157159

passing URIs to video view, 159

setting up VideoView, 157

moving data, 4345

music

binding to music service, 165

cursor loader, 166

finding recent tracks, 165167

Idle state, 162

Initialized state, 162

Loader class, 168169

longer-running, 164

MediaPlayer and state, 162

playing sound effects, 163

playing sounds, 162163

Playing state, 162

Prepared state, 162

music playback

listening for intents, 167169

process, 164

music service, playing audio in, 169174

music software

audio focus, 174

headphone controls, 174

interruptions, 174175

missing SD cards, 175

phone calls, 174

MVC (Model-View-Controller), 65

N

navigation, view pager, 212

navigation drawer

ActionBarDrawerToggle, 220

ActionBarToggleDrawer, 220

demo, 218

explained, 217

onCreate, 218221

onItemClickListener, 219

setContentView, 219

setDisplayHomeAsUpEnabled, 219220

standard icon, 218

swapping fragments, 222

visible shadow, 219

XML, 221

NewActivity class, creating, 27

Next button, 7879

notification, using in communication, 130131

notifyFinished method, 9798

O

onBlind, using with services, 124

onClickListener, setting, 5658

onCompletionListener, calling for audio, 173174

onCreate method

calling order, 3233

navigation drawer, 218221

using with fragments, 192

using with services, 124

view pager, 213214

onCreateView, using with fragments, 192

onDestroy method

calling, 32, 35

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

calling order, 32, 34

using with fragments, 192

onResume method

calling order, 32

using with fragments, 192

onRetainNonConfigurationInstance method, 3536

onSaveInstanceState method, 35

onStart method

invoking, 32

using with fragments, 192

onStartCommand, using with services, 124

onStop method

calling order, 32, 34

using with fragments, 192

OS X

installing Android Studio, 6

installing Eclipse (ADT Bundle), 5

P

packages, naming, 226227

packaging and signing, 228231

packed binary format, 63

padding declaration, 78

page change listener, creating, 214

PendingIntent, flags associated with, 130

physical devices, working with, 1213

picture viewer, 67. See also layout management

play, calling for audio, 172173

playing

media, 160161

sound effects, 163

sounds, 162163

plugin: 'android,' using with Gradle, 237

Prev button, declaring, 78

primitives, saving, 36

product flavors, using with Gradle files, 242243

project type, selecting, 14

projects

creating, 1416

R.java file, 63

running, 1820

view pager, 212

public void

onCreate(), 3334

onResume(), 34

onStart(), 34

px (pixels), 53, 67

R

Reddit data, getting, 112114

RelativeLayout

gray background, 7980

nesting in, 80

Next button, 7879

padding declaration, 78

Prev button, 78

referencing @id/., 77

release build, exporting, 229

repositories, using with Gradle, 237

requestLocationUpdates method, 179180

res folder

contents, 6263

drawable folders, 6263, 6566

layout folders, 62, 6465, 142147

naming conventions, 63

values folder, 62, 64

resource management, 6263

resources, finding, 54

R.java file, 63

S

saving

files to SD cards, 96

primitives, 36

screen layout, creating, 2829

screen sizes, handling, 6566

screen with buttons, 142143

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

creating, 134135

declaring, 9495

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, 169174

setDisplayHomeAsUpEnabled, using with navigation drawer, 219220

SharedPreferences, commit method, 151

signed build, exporting, 228231

signing key, adding to build files, 244245

sound effects, playing, 163

sounds, playing, 162163. See also audio

sp (scaled pixel), 53

startForeground method, using with services, 125

storing files, 9596

StrictMode.enableDefaults(), 99

T

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, 165167

troubleshooting emulator, 21. See also debugging

U

UI (user interface)

altering at runtime, 5355

finding resources, 54

identifying views, 5354

keeping views, 5455

XML vs. Java layouts, 55

unknown sources, allowing, 13

updating

Android SDK, 78

applications frequently, 232233

URIs, passing to video view, 159

USB debugging, enabling, 13

<uses> tag, using with working devices, 150

V

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, 152153

versioning, 227

video view, passing URIs to, 159

VideoView

adding for movies, 156

setting up for movies, 157

View class, explained, 50

view pager

action bar, 212213

ActionBar navigation mode, 214

creating project, 212

explained, 212

FragmentPagerAdapter, 212, 215216

FragmentStatePagerAdapter, 212

onCreate, 213214

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

changing visibility, 5558

customizing extended, 5960

defining in LinearLayout, 7075

dip or dp (device-independent pixels), 53

height and width, 51, 53

identifying, 5354

keeping, 5455

match_parent definition, 53

MATCH_PARENT definition, 53

onClickListener, 5658

px (pixels), 53

retrieving, 54

sp (scaled pixel), 53

using extended, 60

wrap_content definition, 53

WRAP_CONTENT definition, 53

in XML, 5051

virtual device emulator

Snapshot option, 12

troubleshooting, 21

Use Host GPU option, 12

using, 912

visibility, changing for views, 5558

W

width and height, determining for views, 51, 53

Windows

installing Android Studio, 6

installing Eclipse (ADT Bundle), 5

working devices. See also devices

limiting access to, 149151

SDK version number, 150

<uses> tag, 150

X

XML

AbsoluteLayout, 6870

custom views, 6162

editing, 28

vs. Java layouts, 55

match_parent definition, 53

navigation drawer, 221

showing fragments, 194197

view pager, 215

views in, 5051

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

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset