Upload
others
View
8
Download
0
Embed Size (px)
Citation preview
11⁄2 Hour Android Bootcamp
Michiel Helvensteijn
Studievaardigheden, 30-10-2012
Introduction
I was invited to give a presentation for the subject Studievaardigheden at Leiden University: a brief demonstrationof how to develop an Android app. I’m afraid that even with this summary sheet, you will not be able to get thefull benefit of the presentation, because most of it was an actual demonstration inside Eclipse. I just write thesesheets for completeness sake. However, I can highly recommend MarakanaTechTV’s Android Bootcamp Series athttp://www.youtube.com/playlist?list=PLE08A97D36D5A255F
1 The Fundamentals
1.1 MarakanaTechTV’s Android Bootcamp
The FundamentalsHello World!A Real App
MarakanaTechTV’s Android BootcampAndroid PlatformAndroid Programming
The FundamentalsMarakanaTechTV’s Android Bootcamp
http://www.youtube.com/playlist?list=PLE08A97D36D5A255F
Michiel Helvensteijn 11⁄2 Hour Android Bootcamp
This is an excellent series of videos that actually taught me a lot ofthe basics (though that was an earlier iteration of the Bootcamp).They gave me the idea to use the ‘live programming’ format for thispresentation.
Just one thing: those videos can be. . . painfully slow. And 11⁄2hours will probably be way too fast. I give this presentation only togive you a taste of how things look and feel.
Oh, yeah, and I’m stealing a few slides from them (just a few).
1.2 Android Platform
The FundamentalsHello World!A Real App
MarakanaTechTV’s Android BootcampAndroid PlatformAndroid Programming
The FundamentalsAndroid Platform
Version API Level NicknameAndroid 1.0, 1.1 1, 2 Android
Android 1.5 3 Cupcake
Android 1.6 4 Donut
Android 2.0, 2.0.1, 2.1 5, 6, 7 Eclair
Android 2.2 8 FroYo
Android 2.3, 2.3.3 9, 10 Gingerbread
Android 3.0, 3.1, 3.2 11, 12, 13 Honeycomb
Android 4.0.2, 4.0.4 14, 15 Ice Cream Sandwich
Android 4.1.1, 4.2 16, 17 Jelly Bean
Michiel Helvensteijn 11⁄2 Hour Android Bootcamp
The API level is the thing developers actually care about. You wantto target a level as high as possible to be able to offer the best newfeatures; but you want to support a level as low as possible, gracefullydegrading your app so that people with old phones can still use it.
The FundamentalsHello World!A Real App
MarakanaTechTV’s Android BootcampAndroid PlatformAndroid Programming
The FundamentalsAndroid Platform
Michiel Helvensteijn 11⁄2 Hour Android Bootcamp
This is very cool. Android is built upon the Linux Kernel. Only thekernel, mind you.
The Libraries on top of it are all open source and optimized for amobile environment. We don’t care about caching as much, becauseeverything is flash memory. We do care about battery life.
On top of that, we have the Application Framework. This is theonly thing app developers have access to, and this is what correspondsto a specific ‘API Level’.
1.3 Android Programming
The FundamentalsHello World!A Real App
MarakanaTechTV’s Android BootcampAndroid PlatformAndroid Programming
The FundamentalsAndroid Programming
Michiel Helvensteijn 11⁄2 Hour Android Bootcamp
Android programming is Java programming. Most of what you cando with Java, you can do with Android. But the ‘way of working’ cansometimes be quite different.
The FundamentalsHello World!A Real App
MarakanaTechTV’s Android BootcampAndroid PlatformAndroid Programming
The FundamentalsAndroid Programming
Michiel Helvensteijn 11⁄2 Hour Android Bootcamp
You can actually program for Android without any IDE. Everythingis available on the command line. But Eclipse makes the go work in-finitely more smoothly. They’ve put quite some work into the AndroidEclipse plugin. You should probably use it.
The FundamentalsHello World!A Real App
MarakanaTechTV’s Android BootcampAndroid PlatformAndroid Programming
The FundamentalsAndroid Programming
Main Building BlocksActivity
Service
Broadcast Receiver
Content Provider
Intent
Michiel Helvensteijn 11⁄2 Hour Android Bootcamp
Activities are visible screens on the phone. They have layouts, buttons,text and that kind of thing. A Service is a unit that can run code inthe background without necesserily having anything visible (by defaultthey don’t run in a separate thread, though). A Broadcast Receivercan pick up all kinds of signals from the system, other apps - or itself- and react to them in some way (like notifying other parts of theapp). A Content Provider makes data from your app available toother apps, so they can all work with the same data-set. All of thesecommunicate with each other by sending Intents. In this presentationwe only concern ourselves with activities, services and intents.
The FundamentalsHello World!A Real App
MarakanaTechTV’s Android BootcampAndroid PlatformAndroid Programming
The FundamentalsAndroid Programming
ManagersMedia
Internet
Phone
Bluetooth
Notifications
Michiel Helvensteijn 11⁄2 Hour Android Bootcamp
Android has a common pattern of exposing the functionality of thedevice and operating system to app developers: Managers. This slidelists just a few example aspects that can be controlled through Man-agers.
The FundamentalsHello World!A Real App
MarakanaTechTV’s Android BootcampAndroid PlatformAndroid Programming
The FundamentalsAndroid Programming
http://developer.android.com
Michiel Helvensteijn 11⁄2 Hour Android Bootcamp
As an Android developer, there is a single website that will be mostimportant to you. The official API reference on the Android Developerwebsite.
2 Hello World!
The FundamentalsHello World!A Real App
Hello World!
Create a newAndroid Application Project
in Eclipse
Michiel Helvensteijn 11⁄2 Hour Android Bootcamp
The FundamentalsHello World!A Real App
Hello World!
Explore the GUI Designer
Activities
Layouts
Widgets
Toolbars
Properties
Michiel Helvensteijn 11⁄2 Hour Android Bootcamp
The FundamentalsHello World!A Real App
Hello World!
Create and RunHello World 0.1
Michiel Helvensteijn 11⁄2 Hour Android Bootcamp
The FundamentalsHello World!A Real App
Hello World!
Explore App Anatomy (files)
Manifest.xml
Resources in res/
Java code in src/
(Libraries in libs/)
(Assets in assets/)
Michiel Helvensteijn 11⁄2 Hour Android Bootcamp
The FundamentalsHello World!A Real App
Hello World!
Implement Interactivity
Hello World 0.2!
Michiel Helvensteijn 11⁄2 Hour Android Bootcamp
3 A Real App
3.1 Activities
The FundamentalsHello World!A Real App
ActivitiesServicesIntents
A Real AppActivities
Michiel Helvensteijn 11⁄2 Hour Android Bootcamp
Activities have a well-defined lifecycle. App developers cannot directlycontrol this lifecycle (merely hint / request), but can dictate how theiractivity behaves on transitions between phases. For this purpose thereis a set of methods that you can overwrite when you inherit from theActivity class. This way you can always request or release resources,save data or do anything else to make sure your activity behaves prop-erly no matter what the user or the operating system does.
The FundamentalsHello World!A Real App
ActivitiesServicesIntents
A Real AppActivities
Use Logcat; Live Logcat
Log Activity Lifecycle
TAG, you’re it!
Michiel Helvensteijn 11⁄2 Hour Android Bootcamp
The FundamentalsHello World!A Real App
ActivitiesServicesIntents
A Real AppActivities
Create a ‘Real’ App
Michiel Helvensteijn 11⁄2 Hour Android Bootcamp
The FundamentalsHello World!A Real App
ActivitiesServicesIntents
A Real AppActivities
Our Stages of DevelopmentCreate an Activity for scheduling the alarm
Test; Log
Create a Service that can trigger an alarm
Test; Log
Connect the two with Intents
Meh. . . It probably works. . .
Michiel Helvensteijn 11⁄2 Hour Android Bootcamp
The FundamentalsHello World!A Real App
ActivitiesServicesIntents
A Real AppActivities
Create an Activity
for Scheduling the Alarm
Message
Frequency
Period
Michiel Helvensteijn 11⁄2 Hour Android Bootcamp
The FundamentalsHello World!A Real App
ActivitiesServicesIntents
A Real AppActivities
Create a Servicethat can Trigger an Alarm
Michiel Helvensteijn 11⁄2 Hour Android Bootcamp
3.2 Services
The FundamentalsHello World!A Real App
ActivitiesServicesIntents
A Real AppServices
Michiel Helvensteijn 11⁄2 Hour Android Bootcamp
Like activities, services also have a lifecycle, but a much easier one.They are created, started and then destroyed. Nonetheless, it is im-portant that you prepare your service to be killed at any time whenthe OS decides that it needs to kill it to reallocate resources.
The FundamentalsHello World!A Real App
ActivitiesServicesIntents
A Real AppServices
Log Service Lifecycle
Michiel Helvensteijn 11⁄2 Hour Android Bootcamp
The FundamentalsHello World!A Real App
ActivitiesServicesIntents
A Real AppServices
Try IntentService;
it’s easier. . .
Michiel Helvensteijn 11⁄2 Hour Android Bootcamp
The FundamentalsHello World!A Real App
ActivitiesServicesIntents
A Real AppServices
Call a Notificationusing NotificationManager
Michiel Helvensteijn 11⁄2 Hour Android Bootcamp
The FundamentalsHello World!A Real App
ActivitiesServicesIntents
A Real AppServices
Schedule the Notificationusing AlarmManager
Michiel Helvensteijn 11⁄2 Hour Android Bootcamp
3.3 Intents
The FundamentalsHello World!A Real App
ActivitiesServicesIntents
A Real AppIntents
Send our Alarm Informationusing Intent extras
Michiel Helvensteijn 11⁄2 Hour Android Bootcamp
The FundamentalsHello World!A Real App
ActivitiesServicesIntents
A Real AppIntents
Do we have Time?Feature Ideas?
Michiel Helvensteijn 11⁄2 Hour Android Bootcamp
Conclusion
The FundamentalsHello World!A Real App
Conclusion
www.mhelvens.net
Michiel Helvensteijn 11⁄2 Hour Android Bootcamp
Thanks for reading!