May 11, 2015
A N D R O I D W O R K S H O P 1
A N T O N I S K A L I P E T I S - M O B I L E L E A D , S O U R C E L A I R A K A L I P E T I S @ S O U R C E L A I R . C O M , @ A K A L I P E T I S
W H AT T H E S E W O R K S H O P S A R E N O T F O R
• Being a pro in two weeks
!
• Learning without trying
!
• Knowing everything out there
W H AT W E A R E G O I N G T O L E A R N
• General knowledge of the platform
• Simple application creation
• Learn how to search
G O O G L E I S Y O U R F R I E N DA N D S TA C K O V E R F L O W T O O !
A G E N D A
• Intro to OOP and Java
• Intro to the Android Platform
• Setting up Android Studio
• Running a simple application
• Creating a simple layout
W H Y U R O C K S O H A R D ?O B J E C T O R I E N T E D P R O G R A M M I N G
• Code decoupling, enforces code reusability
• Associates data structures with their related methods
• Makes real-world object representation easier
A C L A S SL E T ’ S S A Y I T ’ S A B L U E P R I N T, I T ’ S A W A Y T O R E P R E S E N T D A TA
O B J E C TC E R TA I N D A TA R E P R E S E N TA T I O N , I N M E M O R Y !
C L A S S E X T E N S I O N
• Classes can extend other classes
• They inherit their attributes and methods
• Can extend only one class
public class Car { public int maxSpeed; public int currentSpeed; ! public void accelerate(int speed) { int tmpSpeed = currentSpeed + speed; if (tmpSpeed < maxSpeed) { currentSpeed = tmpSpeed; } else { currentSpeed = maxSpeed; } } } !public class Truck extends Car { public int trailers; public int maxTrailers; ! public void addTrailer() { if (trailers < maxTrailers) { trailers++; } } }
I N T E R FA C E SF U N C T I O N A L I T Y PA C K S - A C T I O N D E S C R I P T I O N S
public class Car { // … } !public interface MilitaryUnit { abstract void startShooting(); } !public class MilitaryCar extends Car implements MilitaryUnit { @Override public void startShooting() { System.out.println("Bang, Bang!"); } }
S O M E O O P L A N G U A G E S
• C++
• Ruby
• Python
• C#
• VB.NET
• ...And, wait for it...
J AVA !L E T ’ S D I V E I N T O …
J AVA AT A G L A N C E
C-like syntax
Created in Sun Microsystems
Now acquired by Oracle
public class HelloWorldJava { public static void main(String[] args) { System.out.prinln("Hello, World!”); } }
G R E AT T H I N G S A B O U T J AVA
• Garbage collector, (almost) good bye memory leaks!
• Shit happens, except exceptions!
• Platform independent, runs on JVM, (or maybe Dalvik!)
– K I T K AT
“Have a break, have a KitKat.”
A N D R O I DE X P L O R I N G T H E W O R L D O F
W H AT I S A N D R O I D
Complete software stack Operating System Middleware Key Applications
Open Source Developed by the Open Handset Alliance
Fastest growing market Platform with the most devices activations
B O T T O M S U PA N D R O I D
A C T I V I T Y
• Creates a window, so that the user can interact with the app
• Can communicate with the system
• Controls the hierarchy of the user interface
A C T I V I T Y L I F E C Y C L E
• Save state
• Know when in foreground
• Know when it is possible to be garbage collected by the system
L E T ’ S S TA R T O U R … F I R S T A P P !
C R E AT E S O M E M O R E V I E W S , E V E N T R Y T O D Y N A M I C A L LY C H A N G E T H E M U S I N G A B U T T O N !
W H A T C A N I P L A Y W I T H ?