Microsoft.Smartphone.Programming
Total Page:16
File Type:pdf, Size:1020Kb
01_762935 ffirs.qxp 11/20/06 7:48 AM Page iii Professional Microsoft® Smartphone Programming Baijian Yang Pei Zheng Lionel M. Ni 01_762935 ffirs.qxp 11/20/06 7:48 AM Page ii 01_762935 ffirs.qxp 11/20/06 7:48 AM Page i Professional Microsoft® Smartphone Programming 01_762935 ffirs.qxp 11/20/06 7:48 AM Page ii 01_762935 ffirs.qxp 11/20/06 7:48 AM Page iii Professional Microsoft® Smartphone Programming Baijian Yang Pei Zheng Lionel M. Ni 01_762935 ffirs.qxp 11/20/06 7:48 AM Page iv Professional Microsoft® Smartphone Programming Published by Wiley Publishing, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2007 by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-0-471-76293-5 Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 1B/QX/RS/QW/IN Library of Congress Cataloging-in-Publication Data: Yang, Baijian, 1972– Microsoft smartphone programming / Baijian Yang, Pei Zheng, Lionel Ni. p. cm. Includes index. ISBN-13: 978-0-471-76293-5 (paper/website) ISBN-10: 0-471-76293-8 (paper/website) 1. Cellular telephones—Computer programs. 2. Pocket computers—Computer programs. 3. Microsoft .NET Frame- work. I. Zheng, Pei, 1972– II. Ni, Lionel M. III. Title. TK6570.M6Y37 2006 621.3845—dc22 2006033469 No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4355, or online at http://www.wiley.com/go/permissions. LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REPRESEN- TATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT LIMITATION WAR- RANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUIT- ABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FURTHER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ. For general information on our other products and services please contact our Customer Care Department within the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002. Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Programmer to Programmer, and related trade dress are trade- marks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. Microsoft is a registered trademark of Microsoft Corporation in the United States and/or other countries. All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. 01_762935 ffirs.qxp 11/20/06 7:48 AM Page v About the Authors Baijian Yang is an assistant professor in the Computer Technology program at Ball State University. He became a Microsoft Certified Systems Engineer (MCSE) in 1998 and was one of the core software designers/developers for etang.com. He received his Ph.D. in Computer Science from Michigan State University in 2002. He is now engaged in research and development in the area of wireless networks and distributed systems. Pei Zheng received his Ph.D. in Computer Science from Michigan State University in 2003. He joined Microsoft as a software engineer in 2005. Before that he was an assistant professor of Computer Science at Arcadia University, and a member of the technical staff at Bell Laboratories, Lucent Technologies. His research interests include distributed systems, network simulation and emulation, and mobile computing. Lionel M. Ni is Chair Professor, Head of the Computer Science and Engineering Department, and Director of the Digital Life Research Center at the Hong Kong University of Science and Technology. Dr. Ni earned his Ph.D. in electrical and computer engineering from Purdue University in 1980. He has been involved in many projects related to wireless technologies, 2.5G/3G cellular phones, and embedded sys- tems. He is co-author of the book Interconnection Networks: An Engineering Approach (Morgan Kaufmann, 2002), and Smart Phone and Next Generation Mobile Computing (Morgan Kaufmann, 2006). 01_762935 ffirs.qxp 11/20/06 7:48 AM Page vi 01_762935 ffirs.qxp 11/20/06 7:48 AM Page vii Credits Senior Acquisitions Editor Graphics and Production Specialists Jim Minatel Carrie A. Foster Brooke Graczyk Development Editor Denny Hager John Sleeva Barbara Moore Rashell Smith Production Editor Alicia B. South William A. Barton Quality Control Technicians Copy Editor Laura Albert Luann Rouff Brian H. Walls Editorial Manager Project Coordinator Mary Beth Wakefield Erin Smith Production Manager Proofreading Tim Tate Techbooks Vice President and Executive Group Publisher Indexing Richard Swadley Infodex Indexing Services, Inc. Vice President and Executive Publisher Joseph B. Wikert 01_762935 ffirs.qxp 11/20/06 7:48 AM Page viii To my wife, Chen Wen —Baijian Yang To my wife, Ning Liu, for her understanding, professional support, and encouragement —Pei Zheng To my dear children, Elaine and Wayland —Lionel M. Ni 01_762935 ffirs.qxp 11/20/06 7:48 AM Page ix Acknowledgments Writing this book required a great deal of effort that went beyond our initial expectations. We would first like to thank our family members, without whose support and encouragement we simply could not finish this book. We also would like to thank the folks at Wiley. Senior Acquisitions Editor Jim Minatel helped us shape our proposal and provided us with professional help at every stage of the project. Thank you very much, Jim, for believing in us and pushing to keep the project on the right track. Development Editor John Sleeva provided us with tons of valuable comments and suggestions, including insightful technical feed- back as well as general writing and formatting guidance. Thank you very much, John, for your extensive professional support and your dedication to keeping the project on a tight schedule. Thanks, also, to Production Editor Bill Barton and Copy Editor Luann Rouff for thoroughly checking and fixing the details of the book, including grammar, format, and layout. Our appreciation also extends to other mem- bers of the Wiley team for your hardworking and consistent contributions to the book. Our special thanks go to Ya-Qin Zhang, the Vice President of Microsoft Corporation. It was his vision and passion in mobile computing that initiated our book project. Besides his inspirations to our work, Ya-Qin has also offered many helps to the book and directed our technical questions to the fellows at Microsoft. We would also like to thank Yong Rui at Microsoft Research for reviewing our work and pro- viding constructive professional opinions. 01_762935 ffirs.qxp 11/20/06 7:48 AM Page x x 02_762935 ftoc.qxp 11/20/06 7:48 AM Page xi Contents Acknowledgments ix Foreword xix Introduction xxi Part I: Smartphone and .NET 1 Chapter 1: Introduction to Microsoft Smartphone 3 What Is a Smartphone? 3 Smartphone Applications and Services 4 Mobile Commerce 5 Mobile Enterprise 5 Mobile Data Service and Entertainment 6 Challenges of Smartphone Application Development 6 Introducing Microsoft Windows Mobile 7 Windows Mobile 5.0 7 Microsoft Smartphone from a User’s Perspective 8 Summary 10 Chapter 2: .NET Compact Framework Fundamentals 11 Introducing the Microsoft .NET Framework 11 The Common Language Runtime 12 .NET Framework Class Libraries 13 Visual Studio 2005 14 Introducing the .NET Compact Framework 15 CLR of the .NET Compact Framework 15 .NET Compact Framework Class Libraries 15 Platform Invoke 16 Smartphone Development Tools 17 .NET Compact Framework Type System 18 Types 19 Attributes and Reflection 21 Generics 21 Exception Handling 21 02_762935 ftoc.qxp 11/20/06 7:48 AM Page xii Contents A Quick Review of C# 22 Value Types 23 Reference Types 24 Operators 25 string and object 26 Classes and Interfaces 28 Polymorphism 32 Arrays and Collections 33 Summary 35 Part II: Smartphone Application Development 37 Chapter 3: Developing Your First Smartphone Application 39 Required Tools 39 Visual Studio