Contents android application development FOR m.tech (jntu - h) i semester - CSE, ii semester - WEB TECHNOLOGIES CONTENTS i UNIT - I [CH. H. - 1] ] [INTRODUCTION TO ANDROID OPERATING SYSTEM]... 1.1-1.32 1.1 INTRODUCTION TO O ANDROID OPERATING SYSTEM... 1.2 1.2 ANDROID OS DESIGN AND FEATURES TURES... 1.5 1.3 ANDROID DEVELOPMENT FRAMEWORK... 1.6 1.3.1 Understanding the Android Software Stack... 1.6 1.3.1.1 The Dalvik Virtual Machine... 1.8 1.3.1.2 Android Application Architecture... 1.8 1.3.1.3 Android Libraries... 1.9 1.4 SDK FEATURES... 1.9 1.5 INSTALLING AND RUNNING APPLICATIONS ON ECLIPSE PLATFORM TFORM... 1.11 1.5.1 Developing for Android... 1.12 1.5.1.1 What you Need To o Begin... 1.12 1.5.1.2 Downloading and Installing the Android SDK... 1.12 1.5.1.3 Downloading and Instilling Updates to the SDK... 1.14 1.5.1.4 Developing with Eclipse... 1.14 1.5.1.5 Using the Android Developer Tools Plug-In For Eclipse... 1.14 1.5.1.6 Using the Support Package... 1.18
ii Contents 1.6 CREATING AVD VD S... 1.18 1.7 TYPES OF ANDROID APPLICATIONS... 1.19 1.8 BEST PRACTICES IN ANDROID PROGRAMMING... 1.20 1.8.1 Creating Your First Android Application... 1.20 1.8.2 Creating Launch Configurations... 1.23 1.8.3 Running and Debugging your Android Application... 1.25 1.9 ANDROID TOOLS... 1.28 UNIT - I [CH. H. - 2] ] [ANDROID APPLICATIONS COMPONENTS AND ACTIVITIES]... 1.33-1.60 2.1 ANDROID APPLICATION COMPONENTS... 1.34 2.2 INTRODUCING THE ANDROID MANIFEST FILE... 1.34 2.2.1 A Closer Look at the Application Manifest... 1.35 2.2.2 Using the Manifest Editor... 1.39 2.3 EXTERNALIZING RESOURCES... 1.40 2.3.1 Creating Resources... 1.41 2.4 RESOURCES FOR DIFFERENT DEVICES AND LANGUAGES... 1.47 2.5 RUNTIME CONFIGURATION CHANGES... 1.49 2.6 ANDROID APPLICATION LIFECYCLE... 1.51 2.6.1 Android Application Priority... 1.51 2.6.2 Application LifeCycle Events... 1.52 2.6.3 Android Activities... 1.54 2.6.3.1 Creating Activities... 1.54 2.6.3.2 The Activity Lifecycle... 1.54 2.6.3.3 Android Activity Classes... 1.59
Contents iii UNIT - II [CH. H. - 3] ] [ANDROID USER INTERFACE]... 2.1-2.40 3.1 MEASUREMENTS... 2.2 3.1.1 Fundamental Android UI Design... 2.2 3.1.2 Android User Interface Fundamentals... 2.2 3.1.2.1 User Interface Layout... 2.3 3.1.3 Assigning User Interfaces to Activities... 2.3 3.1.4 Introducing Layouts... 2.4 3.1.4.1 Defining Layouts... 2.4 3.1.4.2 Using Layouts to Create Device Independent User Interfaces... 2.6 3.2 USER INTERFACE CE (UI) COMPONENTS... 2.9 3.2.1 The Spinner... 2.16 3.2.2 Dialog and Pickers... 2.21 3.2.2.1 Time Picker View... 2.21 3.2.2.2 Displaying the TimePicker in a Dialog Window... 2.23 3.2.2.3 DatePicker... 2.27 3.2.2.4 Using the DatePicker View... 2.27 3.2.2.5 Displaying the Datepicker View in a Dialog Window... 2.31 3.3 EVENT HANDLING... 2.36 3.3.1 Handling Clicks or Changes of Various UI Component... 2.36 3.3.2 How it Works... 2.38
iv Contents UNIT - II [CH. H. - 4] ] [FRAGMENTS FRAGMENTS]... 2.41-2.58 4.1 INTRODUCTION TO FRAGMENTS... 2.42 4.2 CREATING FRAGMENTS... 2.42 4.3 LIFECYCLE OF FRAGMENTS... 2.43 4.3.1 Fragment ragment-specific Lifecycle Events... 2.46 4.3.1.1 Attaching and Detaching Fragments from the Parent Activity... 2.46 4.3.1.2 Creating and Destroying Fragments... 2.47 4.3.1.3 Creating and Destroying User Interface... 2.47 4.3.2 Fragment States... 2.47 4.4 ADDING FRAGMENTS TO ACTIVITY... 2.47 4.4.1 Using Fragment Transactions ransactions... 2.49 4.4.2 Adding,, Removing and Replacing Fragments... 2.49 4.4.3 Using the Fragment Manager to Find ind Fragments ragments... 2.49 4.4.4 Populating Dynamic Activity Layouts with Fragments... 2.50 4.4.5 Fragment and the Back Stack... 2.51 4.4.6 Animating Fragment Transactions ransactions... 2.52 4.5 INTERFACING BETWEEN FRAGMENTS AND ACTIVITIES... 2.52 4.6 MULTI- TI-SCREEN ACTIVITIES CTIVITIES... 2.53 UNIT - III [CH. - 5] ] [INTENT AND BROADCASTS]... 3.1-3.18 5.1 INTRODUCTION TO INTENTS... 3.2 5.2 USING INTENTS TO LAUNCH ACTIVITIES... 3.2 5.3 EXPLICITLY STAR ARTING NEW ACTIVITIES... 3.2 5.4 IMPLICIT INTENTS... 3.3
Contents v 5.5 PASSING DATA A TO INTENTS... 3.3 5.6 GETTING RESULTS FROM ACTIVITIES... 3.6 5.6.1 Launching Sub-Activities... 3.7 5.6.2 Returning Result... 3.7 5.6.3 Handling Sub-Activity Results... 3.8 5.7 NATIVE ACTIONS... 3.9 5.8 USING INTENT TO DIAL A NUMBER OR TO SEND SMS... 3.11 5.8.1 Using Intent to Dial a Number... 3.11 5.8.1.1 Replacing the Native Dialer... 3.11 5.8.2 Using Intent to Send SMS... 3.13 5.8.2.1 Sending SMS Messages Using the SMS Manager... 3.13 5.8.2.2 Tracking and Confirming SMS Message Delivery... 3.14 5.8.2.3 Conforming to Maximum SMS Message Size... 3.16 5.8.2.4 Sending Data Messages... 3.16 UNIT - III [CH. - 6] ] [BROADCAST RECEIVERS]... 3.19-3.26 6.1 INTRODUCTION TO O BROADCAST RECEIVERS... 3.20 6.1.1 Creating the Broadcast Receiver... 3.20 6.1.2 Registering Broadcast Receiver... 3.20 6.2 USING INTENT FILTERS TO SERVICE IMPLICIT INTENTS... 3.21 6.3 RESOLVING INTENT FILTERS... 3.24 6.4 FINDING AND USING INTENTS RECEIVED WITHIN AN ACTIVITY... 3.25
vi Contents UNIT - III [CH. H. - 7] ] [NOTIFICATIONS NOTIFICATIONS]... 3.27-3.42 7.1 INTRODUCTION TO NOTIFICA TIFICATIONS TIONS... 3.28 7.2 CREATING NOTIFICA TIFICATIONS TIONS... 3.29 7.2.1 Creating a Notification and Configuration the Status Bar Display... 3.29 7.2.2 Using the Default Notification Sounds, Lights and Vibrations... 3.29 7.2.3 Making Sounds... 3.30 7.2.4 Vibrating the Device... 3.30 7.2.5 Flashing the Lights... 3.30 7.2.6 Using the Notification Builder... 3.31 7.3 DISPLAYING NOTIFICA TIFICATIONS TIONS... 3.31 7.3.1 Displaying Notifications on the Status Bar... 3.32 7.4 DISPLAYING TOASTS... 3.39 7.4.1 Customizing Toasts... 3.40 7.4.2 Using Toasts in Worker Threads... 3.41 UNIT - IV [CH. - 8] ] [PERSISTENT STORAGE]... 4.1-4.8 8.1 INTRODUCTION TO O FILES... 4.2 8.1.1 Working with File ile System... 4.2 8.1.2 Using Application Specific Folders to Store Files... 4.2 8.1.3 Creating Private Application Files... 4.3 8.1.4 Reading Data from Files... 4.4 8.1.5 Listing Contents of A Directory Shared Preferences... 4.6 8.1.5.1 Creating and Saving Preferences... 4.6 8.1.5.2 Retrieving Shared Resources... 4.7
Contents vii UNIT - IV [CH. H. - 9] ] [DATABASE DATABASE]... 4.9-4.22 9.1 INTRODUCTION TO SQLITE DATABASE ABASE... 4.10 9.2 CREATING AND OPENING A DATABASE ABASE... 4.10 9.2.1 Introducing the SQLiteOpenHelper... 4.11 9.3 REGISTERING CONTENT PROVIDERS... 4.13 9.4 USING CONTENT PROVIDERS... 4.13 9.4.1 Inserting Content... 4.13 9.4.2 Deleting Content... 4.14 9.4.3 Updating Content... 4.15 9.4.4 Retrieve Content... 4.15 UNIT - V [CH. - 10] ] [ADVANCED TOPICS : ALARMS]... 5.1-5.8 10.1 USING ALARMS... 5.2 10.1.1 Creating, Setting and Cancelling Alarms... 5.2 10.1.2 Setting Repeating Alarms... 5.3 10.1.3 Using Repeating Alarms to Schedule Network Refreshes... 5.4 UNIT - V [CH. - 11] ] [USING INTERNET RESOURCES]... 5.9-5.18 11.1 CONNECTING TO O INTERNET RESOURCE... 5.10 11.2 USING DOWNLOAD MANAGER... 5.11 11.2.1 Downloading Files... 5.11 11.2.2 Customizing Download Manager Notifications... 5.13 11.2.3 Specifying a Download Location... 5.14 11.2.4 Cancelling and Removing Downloads... 5.14 11.2.5 Querying The Download Manager... 5.14
viii Contents UNIT - V [CH. H. - 12] ] [LOCATION BASED SERVICES]... 5.19-5.30 12.1 INTRODUCTION TO LOCATION BASED SERVICES... 5.20 12.2 FINDING YOUR CURRENT LOCATION... 5.20 12.2.1 Location Privacy... 5.21 12.2.2 Finding the Last Known Location... 5.21 12.2.3 An Example... 5.21 12.2.4 Refreshing the Current Location... 5.24 12.2.5 Tracking Your Location in Where AM I... 5.27 12.3 UPDATING LOCA OCATION TION... 5.29