Introduction to Android Application Development [Kurniawan & Perry].pdf

(2347 KB) Pobierz
Introduction to
Android Application
Development
First Edition
Budi Kurniawan and Daniel Perry
Introduction to Android Application Development
Copyright © 2014 by Brainy Software Inc.
First Edition: April 2014
All rights reserved. No part of this book may be reproduced or transmitted in any form or
by any means, electronic or mechanical, including photocopying, recording, or by any
information storage and retrieval system, without written permission from the publisher,
except for the inclusion of brief quotations in a review.
ISBN: 978-0-9921330-0-9
Printed in the United States of America
Book and Cover Designer: Brainy Software Team
Technical Reviewer: Paul Deck
Indexer: Chris Mayle
Trademarks
Oracle and Java are registered trademarks of Oracle and/or its affiliates.
UNIX is a registered trademark of The Open Group.
Microsoft Internet Explorer is either a registered trademark or a trademark of Microsoft
Corporation in The United States and/or other countries.
Apache is a trademark of The Apache Software Foundation.
Firefox is a registered trademark of the Mozilla Foundation.
Google is a trademark of Google, Inc.
Throughout this book the printing of trademarked names without the trademark symbol is
for editorial purpose only. We have no intention of infringement of the trademark.
Warning and Disclaimer
Every effort has been made to make this book as accurate as possible. The author and the
publisher shall have neither liability nor responsibility to any person or entity with respect
to any loss or damages arising from the information in this book.
Table of Contents
Introduction..................................................................................................1
Overview...................................................................................................1
Online Reference.......................................................................................2
Downloading and Installing Java..............................................................3
Downloading and Installing Android Development Tools........................7
About This Book.......................................................................................9
Downloading Program Examples..............................................................9
Chapter 1: Your First Application...........................................................11
Creating An Application..........................................................................11
The Android Manifest.............................................................................17
Running An Application on An Emulator...............................................19
Application Structure...............................................................................26
Changing the Application Icon................................................................27
Logging....................................................................................................28
Debugging An Application......................................................................29
Running on A Real Device......................................................................32
Upgrading the SDK.................................................................................33
Summary..................................................................................................34
Chapter 2: Activities..................................................................................35
The Activity Lifecycle.............................................................................35
ActivityDemo Example...........................................................................38
Starting Another Activity........................................................................42
Summary..................................................................................................47
Chapter 3: UI Components.......................................................................49
Overview.................................................................................................49
iv
Introduction to Android Application Development
Using the ADT Eclipse UI Tool..............................................................50
Using Basic Components.........................................................................51
Layouts....................................................................................................56
Summary..................................................................................................57
Chapter 4: Listeners...................................................................................59
Overview.................................................................................................59
Example...................................................................................................60
Summary..................................................................................................63
Chapter 5: The Action Bar........................................................................65
Overview.................................................................................................65
Adding Action Items...............................................................................66
Adding Dropdown Navigation................................................................71
Summary..................................................................................................76
Chapter 6: Animation................................................................................77
Overview.................................................................................................77
Property Animation.................................................................................77
Example...................................................................................................81
Summary..................................................................................................85
Chapter 7: Handling the Handler.............................................................87
Overview.................................................................................................87
Example...................................................................................................88
Summary..................................................................................................92
Chapter 8: The Media Recorder...............................................................93
MediaRecorder........................................................................................93
Example...................................................................................................94
Summary..................................................................................................99
Chapter 9: Asynchronous Tasks.............................................................101
Overview...............................................................................................101
Example.................................................................................................102
Summary................................................................................................108
Index..........................................................................................................109
Introduction
Android is the most popular mobile platform today, and this book is a
gentle introduction to Android programming. You will learn how to create
applications and use the Android APIs in the examples that accompany this
book.
The set of APIs that ship with the Android software development kit
(SDK) are comprehensive. With these APIs you can easily use user
interface (UI) components, play and record audio and video, write games
and animation, store and retrieve data, search the Internet, and so on.
This introduction provides an overview of the Android platform and the
content of this book. It also contains instructions for installing two pieces of
software that you need for Android development, the Java Developer Kit
(JDK) and the ADT Bundle.
Overview
Today Android rules the smartphone and tablet world. One of the reasons
for its rapid ascent to the top is the fact that it uses Java as its programming
language. But, is Android really Java? The answer is yes and no. Yes, Java
is the default programming language for Android application development.
No, Android applications do not run on the Java Virtual Machine as all Java
applications do. Instead, Android applications run on a virtual machine
called Dalvik.
After an Android program is compiled to Java bytecode, the bytecode is
then cross-compiled to a .dex (Dalvik executable) file that contains one or
multiple Java classes. The dex file, the manifest file (an XML file that
describes the application), and all resource files are then packaged using the
Zgłoś jeśli naruszono regulamin