ebook img

Learning Android PDF

268 Pages·2011·9.46 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Learning Android

Learning Android > m o c k. o o b e w o w w. w w < k o o B e w! o W m o d fr a o nl w o D Learning Android Marko Gargenta Beijing • Cambridge • Farnham • Köln • Sebastopol • Tokyo Learning Android by Marko Gargenta Copyright © 2011 Marko Gargenta. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://my.safaribooksonline.com). For more information, contact our corporate/institutional sales department: (800) 998-9938 or [email protected]. Editors: Andy Oram and Brian Jepson Indexer: Jay Marchand Production Editor: Holly Bauer Cover Designer: Karen Montgomery Copyeditor: Genevieve d’Entremont Interior Designer: David Futato Proofreader: Jennifer Knight Illustrator: Robert Romano Printing History: March 2011: First Edition. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. Learning Android, the image of a Little Owl, and related trade dress are trademarks of O’Reilly Media, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions, or for damages resulting from the use of the information con- tained herein. ISBN: 978-1-449-39050-1 [LSI] 1299702297 Table of Contents Preface .................................................................... xiii 1. Android Overview ....................................................... 1 Android Overview 1 Comprehensive 1 Open Source Platform 2 Designed for Mobile Devices 2 History 3 Google’s Motivation 3 Open Handset Alliance 4 Android Versions 4 Summary 5 2. The Stack .............................................................. 7 Stack Overview 7 Linux 7 Portability 7 Security 8 Features 8 Native Libraries 9 Dalvik 9 Android and Java 10 Application Framework 11 Applications 12 The APK 12 Application Signing 12 Application Distribution 12 Summary 13 3. Quick Start ............................................................ 15 Installing the Android SDK 15 v Setting Up a PATH to Tools 16 Installing Eclipse 16 Eclipse Workspace 17 Setting Up Android Development Tools 17 Hello, World 18 Creating a New Project 18 Manifest File 20 Layout XML Code 21 Strings 21 The R File 22 Java Source Code 22 The Emulator 23 An Emulator Versus a Physical Phone 25 Summary 25 4. Main Building Blocks ................................................... 27 What Are Main Building Blocks? 27 A Real-World Example 27 Activities 28 Activity Life Cycle 28 Intents 31 Services 31 Content Providers 32 Broadcast Receivers 34 Application Context 34 Summary 35 5. Yamba Project Overview ................................................ 37 The Yamba Application 37 Design Philosophy 39 Project Design 39 Part 1: Android User Interface 39 Building an Activity 40 Networking and Multithreading 41 Debugging Android Apps 41 Part 2: Preferences, Filesystem, Options Menu, and Intents 41 The Activity 41 Menu System and Intents 42 Filesystem 42 Part 3: Android Services 42 Services 42 Application Object 42 Part 4: Working with Databases 42 vi | Table of Contents SQLite and Android’s Support for It 42 Refactoring the Code Again 43 Part 5: Lists and Adapters 43 Timeline Activity 43 More Refactoring? 43 Part 6: Broadcast Receivers 43 Boot and Network Receivers 44 Timeline Receiver 44 Permissions 44 Part 7: Content Providers 44 Status Data 44 Android Widgets 44 Part 8: System Services 45 Compass and Location 45 > Intent Service, Alarms, and Notifications 45 m o Summary 45 c k. o o eb 6. Android User Interface .................................................. 47 w o Two Ways to Create a User Interface 47 w w. Declarative User Interface 47 w w Programmatic User Interface 48 < k The Best of Both Worlds 48 o Bo Views and Layouts 48 e w! LinearLayout 49 Wo TableLayout 50 m FrameLayout 50 o d fr RelativeLayout 50 a AbsoluteLayout 50 o wnl Starting the Yamba Project 51 o D The StatusActivity Layout 52 Important Widget Properties 54 Strings Resource 55 The StatusActivity Java Class 56 Creating Your Application-Specific Object and Initialization Code 56 Compiling Code and Building Your Projects: Saving Files 59 Adding the jtwitter.jar Library 59 Updating the Manifest File for Internet Permission 61 Logging in Android 62 LogCat 62 Threading in Android 65 Single Thread 65 Multithreaded Execution 66 AsyncTask 67 Table of Contents | vii Other UI Events 70 Adding Color and Graphics 74 Adding Images 74 Adding Color 76 Alternative Resources 79 Optimizing the User Interface 80 Hierarchy Viewer 81 Summary 82 7. Preferences, the Filesystem, the Options Menu, and Intents .................. 83 Preferences 83 Prefs Resource 84 PrefsActivity 87 Update the Manifest File 88 The Options Menu 89 The Menu Resource 89 Android System Resources 90 Update StatusActivity to Load the Menu 91 Update StatusActivity to Handle Menu Events 92 Strings Resource 92 Shared Preferences 93 The Filesystem Explained 95 Exploring the Filesystem 95 Filesystem Partitions 96 System Partition 96 SDCard Partition 96 The User Data Partition 97 Filesystem Security 98 Summary 99 8. Services ............................................................. 101 The Yamba Application Object 102 The YambaApplication Class 102 Update the Manifest File 104 Simplifying StatusActivity 105 UpdaterService 105 Creating the UpdaterService Java Class 106 Update the Manifest File 107 Add Menu Items 108 Update the Options Menu Handling 109 Testing the Service 109 Looping in the Service 110 Testing the Service 113 viii | Table of Contents

Description:
Explains how to use the publish-subscribe mechanism in Android to With a subscription, you can read any page and watch any video from our
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.