Download - Android Application Development Adam Gerber, PhD, SCJP [email protected] Office: Ryerson 154
![Page 1: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/1.jpg)
Android Application Development
Adam Gerber, PhD, [email protected]
Office: Ryerson 154 Office Hours: Mon 8:20pm-10:00pm
TA: Jonathan Nieder
![Page 2: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/2.jpg)
Evaluations
20% homework assignments (4@ 5% each) 20% midterm exam 50% individual final project (take home) 10% class participation
Late homework/final project is penalized 10% every day late, for three days; after that, you get a zero.
![Page 3: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/3.jpg)
lec 01
The Android Computing Platform and Architecture
Setting Up Your Development Environment
Tour of Eclipse/ADT
First App: HelloWorld
Understanding Android Resources
![Page 4: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/4.jpg)
The Android Computing Platform
![Page 5: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/5.jpg)
Android
• Comprehensive open-source platform for mobile devices
• Owned by Open Handset Alliance
• Championed by Google
• Stated goal: "accelerate innovation in mobile and offer consumers a richer, less expensive, and better mobile experience."
![Page 6: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/6.jpg)
Vision for Android
![Page 7: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/7.jpg)
Version API Level Nickname
Android 1.0 1 Android
Android 1.1 2 Android
Android 1.5 3 Cupake
Android 1.6 4 Donut
Android 2.0 5 Eclair
Android 2.01 6 Eclair
Android 2.1 7 Eclair
Android 2.2 8 FroYo
Android 2.3 9 Gingerbread
Android 2.3.3 10 Gingerbread
Android 3.x 11,12,13 Honeycomb
Android 4.0.1 – 4.0.2 14 Ice Cream Sandwich
Android 4.0.3 – 4.0.4 15 Ice Cream Sandwich
![Page 8: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/8.jpg)
![Page 9: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/9.jpg)
http://developer.android.com/resources/dashboard/platform-versions.html
![Page 10: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/10.jpg)
![Page 11: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/11.jpg)
Mods (skins)
![Page 12: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/12.jpg)
Open Handset Alliance
http://en.wikipedia.org/wiki/Android_(operating_system)
http://en.wikipedia.org/wiki/Open_Handset_Alliance
The OHA was established on 5 November 2007, led by Google with 34 members including mobile handset makers, application developers, some mobile carriers and chip makers.
Android, the flagship software of the alliance, is based on an open source license and competes against mobile platforms from Apple, Microsoft, Nokia (Symbian), HP (formerly Palm), Research In Motion, and Samsung Electronics (bada).
Headquarters: South Korea
![Page 13: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/13.jpg)
![Page 14: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/14.jpg)
![Page 15: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/15.jpg)
![Page 16: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/16.jpg)
![Page 17: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/17.jpg)
![Page 18: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/18.jpg)
![Page 19: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/19.jpg)
![Page 20: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/20.jpg)
Setting up your dev enviroment
![Page 21: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/21.jpg)
Getting/Using the tools
Google-search-> java jdk || java se downloads || JDK version 6 || install to c:\java || set the path env variable. C:\path\to\jdk\bin || java -version from command line.
Google-search-> android sdk || install to c:\java\android-sdk || path to C:\java\android-sdk\platform-tools;C:\java\android-sdk\tools; adb devices to test.
Google-search-> eclipse ide | right-side download eclipse get the SE version || portable version so no need to "install" || dnd in root of c
Google-search-> adt eclipse || half way down to red url, and copy it. | within eclispe help || install new software || paste in there.
within eclipse || little-down arrow || opens And SdK manager 4.0.3
within eclipse || little=phone-icon || pulls up AVDM new
http://www.classes.cs.uchicago.edu/archive/2012/summer/51031-1/android-src.zip C:\java\android-sdk\platforms\android-15\sources\android-src.zip
![Page 22: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/22.jpg)
Quick Java Review
![Page 23: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/23.jpg)
Java Primitives (integers)Type Signed? Bits Bytes Lowest Highest
byte signed 8 1 -27
-128 27-1+127
short signed 16 2 -215
-32,768 215-132,767
int signed 32 4-231
-2,147,483,648 231-1 2,147,483,647
long signed 64 8
-263
-9, 223,372,036,854,775,808
263-19,223,372,036,854,775,807
![Page 24: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/24.jpg)
How Java Stores positive Integers
-2(bits -1) to 2(bits -1) – 1•0001 0011•The above is a binary representation of the number 19 stored in a byte (8 bits).•The range of a byte is: -128 to 127.
![Page 25: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/25.jpg)
Type Signed? Bits Bytes Lowest Highest
boolean n/a 1 1 false true
char unsigned Unicode 16 2 0
'\u0000' 216-1'\uffff'
float
signed exponent and mantissa
32 4 ±1.40129846432481707e-45
±3.40282346638528860e+38with 6 to 7 significant digits of accuracy.
double
signed exponent and mantissa
64 8 ±4.94065645841246544e-324
±1.79769313486231570e+308with 14 to 15 significant digits of accuracy.
Java Primitives (others)
![Page 26: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/26.jpg)
Primitives versus ObjectsmemoryPrimitives Objects
Variables store values and are allocated memory depending on their type. How much?...refer to Java Primitives slide.
References store memory addresses. The size of the allocation for the object reference is VM specific, but is usually the native pointer size; 32bits in 32-bit VM, and 64bits in a 64-bit VM.
Garbage collected when out-of-scope. Garbage collected when out-of-scope.
Passed into methods by value Passed into methods by reference (value of the address is passed)
![Page 27: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/27.jpg)
primitive objectpass by value pass by reference
Action: Tell my accountant how much I intend to spend on a new car next year. Change in bank account: no change.
Action: Swipe debit card and enter pin at the Bently dealership. Change in bank account: -125k.
![Page 28: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/28.jpg)
Class Objects
![Page 29: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/29.jpg)
Class Objects
![Page 30: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/30.jpg)
Spot the “class” here
![Page 31: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/31.jpg)
Naming conventions
![Page 32: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/32.jpg)
Naming local variables - suggestions
boolean bFlagbyte yAgechar cFirstshort sRosterSizeint nStudent; nClong lPopulationfloat fPricedouble dDistanceToMoon
![Page 33: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/33.jpg)
Naming local references - suggestions
Person per perDirectorString str strFirstNameRectangle rec recShapeBee bee beeDrone
![Page 34: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/34.jpg)
Naming local arrays and collections - suggestions
Array of boolean bAnswersArray of byte yAgesArray of int nIdentitiesArray of Person perStudentsArray of String strCountriesCollection of Bee such as ArrayList<Bee> beeDronesCollection of Athlete athPlayers
![Page 35: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/35.jpg)
Why use a naming convention? metadata is immediately discernible just by looking
at the local variable or local reference name. This makes your code easy to read and debug.
Primitives always have one letter prefix; nNumber References have three letter prefix; perDirector. Arrays and collections have s postfix: beeDrones;
strCountries, nLevels. Avoid ending with s for variables or references that
are NOT collections/arrays; e.g. nRadiux, or nRadius_
Overridden methods in Android come with their own set of params.
![Page 36: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/36.jpg)
Eclipse IDE
![Page 37: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/37.jpg)
Shortucts:
New class and browse to superclass ActivityCntrl-numeric 1 is QuickFix!Control click to source.
Source || override/implements methods
Extract method Create getters and setters
Templates || see videoWindow || preferences || Java || Editor || Templates
Ctrl-Shift-L
![Page 38: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/38.jpg)
Using the debugger
Perspectives; Java and Debug Setting breakpoints Step-over F6, and Step-in F5 Watch expressions Conditional breakpoints
![Page 39: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/39.jpg)
Resources in Android
![Page 40: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/40.jpg)
Alt-Shift-A to externalize strings
<st + ctrl space Create many xml resources, but don't name the actual resources the same
Add resources from the Add Resources from the graphical editor and also manually. #FFFFFF white
getResources(). getStringArray(R.array.whatever)
![Page 41: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/41.jpg)
Building Blocks of an App
• Activities
• Intents
• Services
• Content Providers
• Broadcast Recievers
![Page 42: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/42.jpg)
Some Developer Resources
![Page 43: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/43.jpg)
![Page 44: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/44.jpg)
Dev Guide
• http://developer.android.com/guide/topics/fundamentals.html
• http://developer.android.com/training/index.html
![Page 45: Android Application Development Adam Gerber, PhD, SCJP gerber@cs.uchicago Office: Ryerson 154](https://reader036.vdocuments.us/reader036/viewer/2022062500/56815118550346895dbf37a2/html5/thumbnails/45.jpg)
Turning in AssignmentsUse git