Notifikasi
Tidak ada notifikasi baru.

Android Programming Tutorials Ver 2.9 - Free download Android Tutorial


Welcome to the Warescription !



We hope you enjoy this digital book and its updates – keep tabs on the
Warescription feed off the CommonsWare site to learn when new editions
of this book, or other books in your Warescription, are available.
Each Warescription digital book is licensed for the exclusive use of its
subscriber and is tagged with the subscribers name. We ask that you not
distribute these books. If you work for a firm and wish to have several
employees have access, enterprise Warescriptions are available. Just contact
us at enterprise@commonsware.com.
Also, bear in mind that eventually this edition of this title will be released
under a Creative Commons license – more on this in the preface.
Remember that the CommonsWare Web site has errata and resources (e.g.,
source code) for each of our titles. Just visit the Web page for the book you
are interested in and follow the links..
You can search through the PDF using most PDF readers (e.g., Adobe
Reader). If you wish to search all of the CommonsWare books at once, and
your operating system does not support that directly, you can always
combine the PDFs into one, using tools like PDF Split-And-Merge or the
Linux command pdftk *.pdf cat output combined.pdf.
Some notes for first-generation Kindle users:
• You may wish to drop your font size to level 2 for easier reading
xvii
This document is licensed for Keith Rasmussen's exclusive use by CommonsWare, LLC
• Source code listings are incorporated as graphics so as to retain the
monospace font, though this means the source code listings do not
honor changes in Kindle font size
xviii
This document is licensed for Keith Rasmussen's exclusive use by CommonsWare, LLC
Preface
Welcome to the Book!
If you come to this book after having read its companion volumes, The
Busy Coder's Guide to Android Development and The Busy Coder's Guide to
Advanced Android Development, thanks for sticking with the series!
CommonsWare aims to have the most comprehensive set of Android
development resources (outside of the Open Handset Alliance itself), and
we appreciate your interest.
If you come to this book having learned about Android from other sources,
thanks for joining the CommonsWare community!
Prerequisites
This book is a collection of tutorials, walking you through developing
Android applications, from the simplest "Hello, world!" to applications
using many advanced Android APIs.
Since this book only supplies tutorials, you will want something beyond
it as a reference guide. That could be simply the Android SDK
documentation, available with your SDK installation or online. It could be
the other books in the CommonsWare Android series. Or, it could be
another Android book – a list of currently-available Android books can be
found on the Android Programming knol. What you do not want to do is
xix
This document is licensed for Keith Rasmussen's exclusive use by CommonsWare, LLC
attempt to learn all of Android solely from these tutorials, as they will
demonstrate the breadth of the Android API but not its depth.
Also, the tutorials themselves have varying depth. Early on, there is more
"hand-holding" to explain every bit of what needs to be done (e.g., classes
to import). As the tutorials progress, some of the simpler Java bookkeeping
steps are left out of the instructions – such as exhaustive lists of import
statements – so the tutorials can focus on the Android aspects of the code.
You can find out when new releases of this book are available via:
• The cw-android Google Group, which is also a great place to ask
questions about the book and its examples
• The commonsguy Twitter feed
• The CommonsBlog
• The Warescription newsletter, which you can subscribe to off of
your Warescription page
Using the Tutorials
Each tutorial has a main set of step-by-step instructions, plus an "Extra
Credit" section. The step-by-step instructions are intended to guide you
through creating or extending Android applications, including all code you
need to enter and all commands you need to run. The "Extra Credit"
sections, on the other hand, provide some suggested areas for
experimentation beyond the base tutorial, without step-by-step
instructions.
If you wish to start somewhere in the middle of the book, or if you only
wish to do the "Extra Credit" work, or if you just want to examine the
results without doing the tutorials directly yourself, you can download the
results of each tutorial's step-by-step instructions from the book's github
repository. You can either clone the repository, or click the Download
Source button in the upper-right to get the source as a ZIP file. The source
code is organized by tutorial number, so you can readily find the project(s)
associated with a particular tutorial from the book.
xx
This document is licensed for Keith Rasmussen's exclusive use by CommonsWare, LLC
The tutorials do not assume you are using Eclipse, let alone any other
specific editor or debugger. The instructions included in the tutorials will
speak in general terms when it comes to tools outside of those supplied by
the Android SDK itself.
The code for the tutorials has been tested most recently on Android 2.2. It
should work on older versions as well, on the whole.
The tutorials include instructions for both Linux and Windows XP. OS X
developers should be able to follow the Linux instructions in general,
making slight alterations as needed for your platform. Windows Vista users
should be able to follow the Windows XP instructions in general, tweaking
the steps to deal with Vista's directory structure and revised Start menu.
If you wish to use the source code from the CommonsWare Web site, bear
in mind a few things:
1. The projects are set up to be built by Ant, not by Eclipse. If you wish
to use the code with Eclipse, you will need to create a suitable
Android Eclipse project and import the code and other assets.
2. You should delete build.xml, then run android update project
-p ... (where ... is the path to a project of interest) on those
projects you wish to use, so the build files are updated for your
Android SDK version.
Also, please note that the tutorials are set up to work well on HVGA and
larger screen sizes. Using them on QVGA or similar sizes is not
recommended.
Warescription
This book will be published both in print and in digital form. The digital
versions of all CommonsWare titles are available via an annual subscription
– the Warescription.
The Warescription entitles you, for the duration of your subscription, to
digital forms of all CommonsWare titles, not just the one you are reading.
xxi
This document is licensed for Keith Rasmussen's exclusive use by CommonsWare, LLC
Presently, CommonsWare offers PDF and Kindle; other digital formats will
be added based on interest and the openness of the format.
Each subscriber gets personalized editions of all editions of each title: both
those mirroring printed editions and in-between updates that are only
available in digital form. That way, your digital books are never out of date
for long, and you can take advantage of new material as it is made available
instead of having to wait for a whole new print edition. For example, when
new releases of the Android SDK are made available, this book will be
quickly updated to be accurate with changes in the APIs.
From time to time, subscribers will also receive access to subscriber-only
online material, including not-yet-published new titles.
Also, if you own a print copy of a CommonsWare book, and it is in good
clean condition with no marks or stickers, you can exchange that copy for a
free four-month Warescription.
If you are interested in a Warescription, visit the Warescription section of
the CommonsWare Web site.
What's New
For those of you who have a Warescription, or otherwise have been keeping
up with this book, here is what is new in this version:
• The Patchy examples were tweaked to use identi.ca instead of
Twitter, due to the latter's change in authentication schemes
• The tutorials were tested on Android 2.2
About the "Further Reading" Sections
Each tutorial has, at the end, a section named "Further Reading". Here, we
list places to go learn more about the theory behind the techniques
illustrated in the preceding tutorial. Bear in mind, however, that the
Internet is fluid, so links may not necessarily work. And, of course, there is
no good way to link to other books. Hence, the "Further Reading" section
describes where you can find material, but actually getting there may
xxii
This document is licensed for Keith Rasmussen's exclusive use by CommonsWare, LLC
require a few additional clicks on your part. We apologize for the
inconvenience.
Errata and Book Bug Bounty
Books updated as frequently as CommonsWare's inevitably have bugs.
Flaws. Errors. Even the occasional gaffe, just to keep things interesting. You
will find a list of the known bugs on the errata page on the CommonsWare
Web site.
But, there are probably even more problems. If you find one, please let us
know!
Be the first to report a unique concrete problem in the current digital
edition, and we'll give you a coupon for a six-month Warescription as a
bounty for helping us deliver a better product. You can use that coupon to
get a new Warescription, renew an existing Warescription, or give the
coupon to a friend, colleague, or some random person you meet on the
subway.
By "concrete" problem, we mean things like:
• Typographical errors
• Sample applications that do not work as advertised, in the
environment described in the book
• Factual errors that cannot be open to interpretation
By "unique", we mean ones not yet reported. Each book has an errata page
on the CommonsWare Web site; most known problems will be listed there.
One coupon is given per email containing valid bug reports.
NOTE: Books with version numbers lower than 0.9 are ineligible for the
bounty program, as they are in various stages of completion. We appreciate
bug reports, though, if you choose to share them with us.
We appreciate hearing about "softer" issues as well, such as:
xxiii
This document is licensed for Keith Rasmussen's exclusive use by CommonsWare, LLC
• Places where you think we are in error, but where we feel our
interpretation is reasonable
• Places where you think we could add sample applications, or
expand upon the existing material
• Samples that do not work due to "shifting sands" of the underlying
environment (e.g., changed APIs with new releases of an SDK)
However, those "softer" issues do not qualify for the formal bounty
program.
Questions about the bug bounty, or problems you wish to report for bounty
consideration, should be sent to CommonsWare.
Source Code License
The source code samples shown in this book are available for download
from the book's GitHub repository. All of the Android projects are licensed
under the Apache 2.0 License, in case you have the desire to reuse any of it.
Creative Commons and the Four-to-Free
(42F) Guarantee
Each CommonsWare book edition will be available for use under the
Creative Commons Attribution-Noncommercial-Share Alike 3.0 license as
of the fourth anniversary of its publication date, or when 4,000 copies of
the edition have been sold, whichever comes first. That means that, once
four years have elapsed (perhaps sooner!), you can use this prose for noncommercial
purposes. That is our Four-to-Free Guarantee to our readers
and the broader community. For the purposes of this guarantee, new
Warescriptions and renewals will be counted as sales of this edition,
starting from the time the edition is published.
This edition of this book will be available under the aforementioned
Creative Commons license on June 1, 2014. Of course, watch the
CommonsWare Web site, as this edition might be relicensed sooner based
on sales.
xxiv
This document is licensed for Keith Rasmussen's exclusive use by CommonsWare, LLC
For more details on the Creative Commons Attribution-Noncommercial-
Share Alike 3.0 license, visit the Creative Commons Web site.
Note that future editions of this book will become free on later dates, each
four years from the publication of that edition or based on sales of that
specific edition. Releasing one edition under the Creative Commons license
does not automatically release all editions under that license.
Lifecycle of a CommonsWare Book
CommonsWare books generally go through a series of stages.
First are the pre-release editions. These will have version numbers below
0.9 (e.g., 0.2). These editions are incomplete, often times having but a few
chapters to go along with outlines and notes. However, we make them
available to those on the Warescription so they can get early access to the
material.
Release candidates are editions with version numbers ending in ".9" (0.9,
1.9, etc.). These editions should be complete. Once again, they are made
available to those on the Warescription so they get early access to the
material and can file bug reports (and receive bounties in return!).
Major editions are those with version numbers ending in ".0" (1.0, 2.0, etc.).
These will be first published digitally for the Warescription members, but
will shortly thereafter be available in print from booksellers worldwide.
Versions between a major edition and the next release candidate (e.g., 1.1,
1.2) will contain bug fixes plus new material. Each of these editions should
also be complete, in that you will not see any "TBD" (to be done) markers
or the like. However, these editions may have bugs, and so bug reports are
eligible for the bounty program, as with release candidates and major
releases.
A book usually will progress fairly rapidly through the pre-release editions
to the first release candidate and Version 1.0 – often times, only a few
months. Depending on the book's scope, it may go through another cycle of
significant improvement (versions 1.1 through 2.0), though this may take
xxv
This document is licensed for Keith Rasmussen's exclusive use by CommonsWare, LLC
several months to a year or more. Eventually, though, the book will go into
more of a "maintenance mode", only getting updates to fix bugs and deal
with major ecosystem events – for example, a new release of the Android
SDK will necessitate an update to all Android books.
Roster of Tutorials
Here is what you can expect in going through the tutorials in this book:
1. We start off with a simple throwaway project, just to make sure you
have the development tools all set up properly.
2. We then begin creating LunchList, an application to track
restaurants where you might wish to go for lunch. In this tutorial,
we set up a simple form to collect basic information about a
restaurant, such as a name and address.
3. We expand the form to add radio buttons for the type of restaurant
(e.g., takeout).
4. Instead of tracking just a single restaurant, we add support for a list
of restaurants – but each restaurant shows up in the list only
showing its name.
5. We extend the list to show the name and address of each restaurant,
plus an icon for the restaurant type.
6. To give us more room, we split the UI into two tabs, one for the list
of restaurants, and one for the detail form for a restaurant.
7. We experiment with an option menu (the kind that appears when
you press the MENU button on a phone) and display a pop-up
message.
8. We learn how to start a background thread and coordinate
communications between the background thread and the main
("UI") thread.
9. We learn how to find out when the activity is going off-screen,
stopping and restarting our background thread as needed.
10. We create a separate UI description for what the tabs should look
like when the phone is held in a landscape orientation.
xxvi
This document is licensed for Keith Rasmussen's exclusive use by CommonsWare, LLC
11. We finally add database support, so your restaurant data persists
from run to run of the application.
12. We eliminate the tabs and split the UI into two separate screens
("activities"), one for the list of restaurants, and one for the detail
form to add or edit a restaurant.
13. We establish a shared preference – and an activity to configure it –
to allow the user to specify the sort order of the restaurants in the
list.
14. We re-establish the landscape version of our UI (lost when we
eliminated the tabs in Tutorial 12) and experiment with how to
handle the orientation changing during execution of our
application.
15. We put LunchList on hold and start up a brand new project, Patchy,
for accessing identi.ca.
16. We integrate the JTwitter JAR – an open source Java API for Twitter
and things supporting the Twitter API – into our application.
17. We add a partial implementation of a service to the application, one
that will periodically poll identi.ca for timeline updates.
18. We fully integrate the service from Tutorial 17 into the application,
showing the timeline updates in a list in the main activity.
19. We split the service out into a separate project, accessed as a
"remote service" using inter-process communication (IPC).
20. We add logic to the service to watch for posts from specific people
– our "BFFs" – and display an icon in the status bar when we see
such a post.
21. We add a menu choice to allow the user to inject their current
location (latitude and longitude) into the status update they are
editing.
22. We watch for locations embedded in posts – akin to those created
in Tutorial 21 – and, if the user clicks on a post in the timeline with
such a location, we display that location on a map.
23. We add a "helpcast" video to our application, to demonstrate video
playback integration.
xxvii
This document is licensed for Keith Rasmussen's exclusive use by CommonsWare, LLC
24. We supplement the "helpcast" with a more traditional help page, in
HTML format, show in an embedded WebKit browser.
25. We extend the help page to pull our identi.ca screen name in for
customization, by building a bridge between the Javascript in the
Web page and the Android Java environment.
26. We give the user a menu option to hide and show the widgets
associated with updating the identi.ca status, then arrange to
animate hiding and showing those widgets.
27. We replace the callback system used previously in our application
with one that uses broadcast Intent objects.
28. We integrate our application into the contacts engine, so posts
from people who also our in our contacts database are highlighted.
29. Back in Patchy, we start monitoring for when Android says the
battery level changes, so when it gets low enough, we scale back the
frequency of our polls for timeline updates.
30. We have Patchy's service monitor for timeline updates via a
scheduled "alarm" rather than via a background thread sleeping for
a certain amount of time.
31. We tie LunchList's restaurant database into the Android search
framework, so you can find a restaurant by name.
32. We create another project, one that will allow us to pick a contact
out of the contact database, then find out what activities can be
launched that know how to do something with that contact.
33. We create a simple app widget (i.e., interactive element for the
home screen) for LunchList, one that displays the name of a
randomly-selected restaurant.
34. We extend the app widget to allow the user to click a button to
choose a different restaurant and click the name of the restaurant to
pull up the LunchList detail form for that restaurant.
35. We test the LunchList application using the Test Monkey,
simulating random input into the UI.
36. We allow users to provide phone numbers for restaurants, then add
in phone-dialing capability to LunchList.
xxviii
This document is licensed for Keith Rasmussen's exclusive use by CommonsWare, LLC
37. We (pretend to) allow users to take pictures of restaurants using
the device's built-in camera.
38. We wrap up by allowing users to randomly select a restaurant by
shaking their phone while running the LunchList application.
39. We allow users to send the name and address of a restaurant to
others via SMS.
40. We fix up the SMS code to support both Android 1.x and Android



Technology And Tutorials
Join the conversation
Post a Comment