




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
a book helpful for develop a app
Typology: Study Guides, Projects, Research
1 / 720
This page cannot be seen from the preview
Don't miss anything!





























































































Android Studio Development Essentials – Android 6 Edition
© 2015 Neil Smyth. All Rights Reserved.
This book is provided for personal use only. Unauthorized use, reproduction and/or distribution strictly prohibited. All rights reserved.
The content of this book is provided for informational purposes only. Neither the publisher nor the author offers any warranties or representation, express or implied, with regard to the accuracy of information contained in this book, nor do they accept any liability for any loss or damage arising from any errors or omissions.
This book contains trademarked terms that are used solely for editorial purposes and to the benefit of the respective trademark owner. The terms used within this book are not intended as infringement of any trademarks.
Rev: 1.
4.7 Summary
5.Creating an Android Virtual Device (AVD) in Android Studio
5.1 About Android Virtual Devices 5.2 Creating a New AVD 5.3 Starting the Emulator 5.4 Running the Application in the AVD 5.5 Run/Debug Configurations 5.6 Stopping a Running Application 5.7 AVD Command-line Creation 5.8 Android Virtual Device Configuration Files 5.9 Moving and Renaming an Android Virtual Device 5.10 Summary
6.Testing Android Studio Apps on a Physical Android Device
6.1 An Overview of the Android Debug Bridge (ADB) 6.2 Enabling ADB on Android 6.0 based Devices 6.2.1 Mac OS X ADB Configuration 6.2.2 Windows ADB Configuration 6.2.3 Linux adb Configuration 6.3 Testing the adb Connection 6.4 Summary
7.The Basics of the Android Studio Code Editor
7.1 The Android Studio Editor 7.2 Splitting the Editor Window 7.3 Code Completion 7.4 Statement Completion 7.5 Parameter Information 7.6 Code Generation 7.7 Code Folding 7.8 Quick Documentation Lookup 7.9 Code Reformatting 7.10 Summary
8.An Overview of the Android Architecture
8.1 The Android Software Stack 8.2 The Linux Kernel 8.3 Android Runtime – ART 8.4 Android Libraries 8.4.1 C/C++ Libraries 8.5 Application Framework 8.6 Applications 8.7 Summary
9.The Anatomy of an Android Application
9.1 Android Activities
9.2 Android Intents 9.3 Broadcast Intents 9.4 Broadcast Receivers 9.5 Android Services 9.6 Content Providers 9.7 The Application Manifest 9.8 Application Resources 9.9 Application Context 9.10 Summary
10.Understanding Android Application and Activity Lifecycles
10.1 Android Applications and Resource Management 10.2 Android Process States 10.2.1 Foreground Process 10.2.2 Visible Process 10.2.3 Service Process 10.2.4 Background Process 10.2.5 Empty Process 10.3 Inter-Process Dependencies 10.4 The Activity Lifecycle 10.5 The Activity Stack 10.6 Activity States 10.7 Configuration Changes 10.8 Handling State Change 10.9 Summary
11.Handling Android Activity State Changes
11.1 The Activity Class 11.2 Dynamic State vs. Persistent State 11.3 The Android Activity Lifecycle Methods 11.4 Activity Lifetimes 11.5 Summary
12.Android Activity State Changes by Example
12.1 Creating the State Change Example Project 12.2 Designing the User Interface 12.3 Overriding the Activity Lifecycle Methods 12.4 Filtering the LogCat Panel 12.5 Running the Application 12.6 Experimenting with the Activity 12.7 Summary
13.Saving and Restoring the State of an Android Activity
13.1 Saving Dynamic State 13.2 Default Saving of User Interface State 13.3 The Bundle Class 13.4 Saving the State
18.3 Creating the GridLayout Project 18.4 Creating the GridLayout Instance 18.5 Adding Views to GridLayout Cells 18.6 Moving and Deleting Rows and Columns 18.7 Implementing Cell Row and Column Spanning 18.8 Changing the Gravity of a GridLayout Child 18.9 Summary
19.Working with the Android GridLayout using XML Layout Resources
19.1 GridLayouts in XML Resource Files 19.2 Adding Child Views to the GridLayout 19.3 Declaring Cell Spanning, Gravity and Margins 19.4 Summary
20.An Overview and Example of Android Event Handling
20.1 Understanding Android Events 20.2 Using the android:onClick Resource 20.3 Event Listeners and Callback Methods 20.4 An Event Handling Example 20.5 Designing the User Interface 20.6 The Event Listener and Callback Method 20.7 Consuming Events 20.8 Summary
21.Android Touch and Multi-touch Event Handling
21.1 Intercepting Touch Events 21.2 The MotionEvent Object 21.3 Understanding Touch Actions 21.4 Handling Multiple Touches 21.5 An Example Multi-Touch Application 21.6 Designing the Activity User Interface 21.7 Implementing the Touch Event Listener 21.8 Running the Example Application 21.9 Summary
22.Detecting Common Gestures using the Android Gesture Detector Class
22.1 Implementing Common Gesture Detection 22.2 Creating an Example Gesture Detection Project 22.3 Implementing the Listener Class 22.4 Creating the GestureDetectorCompat Instance 22.5 Implementing the onTouchEvent() Method 22.6 Testing the Application 22.7 Summary
23.Implementing Custom Gesture and Pinch Recognition on Android
23.1 The Android Gesture Builder Application 23.2 The GestureOverlayView Class
23.3 Detecting Gestures 23.4 Identifying Specific Gestures 23.5 Building and Running the Gesture Builder Application 23.6 Creating a Gestures File 23.7 Extracting the Gestures File from the SD Card 23.8 Creating the Example Project 23.9 Adding the Gestures File to the Project 23.10 Designing the User Interface 23.11 Loading the Gestures File 23.12 Registering the Event Listener 23.13 Implementing the onGesturePerformed Method 23.14 Testing the Application 23.15 Configuring the GestureOverlayView 23.16 Intercepting Gestures 23.17 Detecting Pinch Gestures 23.18 A Pinch Gesture Example Project 23.19 Summary
24.An Introduction to Android Fragments
24.1 What is a Fragment? 24.2 Creating a Fragment 24.3 Adding a Fragment to an Activity using the Layout XML File 24.4 Adding and Managing Fragments in Code 24.5 Handling Fragment Events 24.6 Implementing Fragment Communication 24.7 Summary
25.Using Fragments in Android Studio - An Example
25.1 About the Example Fragment Application 25.2 Creating the Example Project 25.3 Creating the First Fragment Layout 25.4 Creating the First Fragment Class 25.5 Creating the Second Fragment Layout 25.6 Adding the Fragments to the Activity 25.7 Making the Toolbar Fragment Talk to the Activity 25.8 Making the Activity Talk to the Text Fragment 25.9 Testing the Application 25.10 Summary
26.Creating and Managing Overflow Menus on Android
26.1 The Overflow Menu 26.2 Creating an Overflow Menu 26.3 Displaying an Overflow Menu 26.4 Responding to Menu Item Selections 26.5 Creating Checkable Item Groups 26.6 Creating the Example Project
30.10 Adding an Action to the Snackbar 30.11 Summary
31.Creating a Tabbed Interface using the TabLayout Component
31.1 An Introduction to the ViewPager 31.2 An Overview of the TabLayout Component 31.3 Creating the TabLayoutDemo Project 31.4 Creating the First Fragment 31.5 Duplicating the Fragments 31.6 Adding the TabLayout and ViewPager 31.7 Creating the Pager Adapter 31.8 Performing the Initialization Tasks 31.9 Testing the Application 31.10 Customizing the TabLayout 31.11 Displaying Icon Tab Items 31.12 Summary
32.Working with the RecyclerView and CardView Widgets
32.1 An Overview of the RecyclerView 32.2 An Overview of the CardView 32.3 Adding the Libraries to the Project 32.4 Summary
33.An Android RecyclerView and CardView Tutorial
33.1 Creating the CardDemo Project 33.2 Removing the Floating Action Button 33.3 Adding the RecyclerView and CardView Libraries 33.4 Designing the CardView Layout 33.5 Adding the RecyclerView 33.6 Creating the RecyclerView Adapter 33.7 Adding the Image Files 33.8 Initializing the RecyclerView Component 33.9 Testing the Application 33.10 Responding to Card Selections 33.11 Summary
34.Working with the AppBar and Collapsing Toolbar Layouts
34.1 The Anatomy of an AppBar 34.2 The Example Project 34.3 Coordinating the RecyclerView and Toolbar 34.4 Introducing the Collapsing Toolbar Layout 34.5 Changing the Title and Scrim Color 34.6 Summary
35.Implementing an Android Navigation Drawer
35.1 An Overview of the Navigation Drawer 35.2 Opening and Closing the Drawer
35.3 Responding to Drawer Item Selections 35.4 Using the Navigation Drawer Activity Template 35.5 Creating the Navigation Drawer Template Project 35.6 The Template Layout Resource Files 35.7 The Header Coloring Resource File 35.8 The Template Menu Resource File 35.9 The Template Code 35.10 Running the App 35.11 Summary
36. An Android Studio Master/Detail Flow Tutorial
36.1 The Master/Detail Flow 36.2 Creating a Master/Detail Flow Activity 36.3 The Anatomy of the Master/Detail Flow Template 36.4 Modifying the Master/Detail Flow Template 36.5 Changing the Content Model 36.6 Changing the Detail Pane 36.7 Modifying the WebsiteDetailFragment Class 36.8 Modifying the WebsiteListActivity Class 36.9 Adding Manifest Permissions 36.10 Running the Application 36.11 Summary
37.An Overview of Android Intents
37.1 An Overview of Intents 37.2 Explicit Intents 37.3 Returning Data from an Activity 37.4 Implicit Intents 37.5 Using Intent Filters 37.6 Checking Intent Availability 37.7 Summary
38.Android Explicit Intents – A Worked Example
38.1 Creating the Explicit Intent Example Application 38.2 Designing the User Interface Layout for ActivityA 38.3 Creating the Second Activity Class 38.4 Designing the User Interface Layout for ActivityB 38.5 Reviewing the Application Manifest File 38.6 Creating the Intent 38.7 Extracting Intent Data 38.8 Launching ActivityB as a Sub-Activity 38.9 Returning Data from a Sub-Activity 38.10 Testing the Application 38.11 Summary
39.Android Implicit Intents – A Worked Example
39.1 Creating the Android Studio Implicit Intent Example Project
43.3 Adding the Service to the Manifest File 43.4 Starting the Service 43.5 Testing the IntentService Example 43.6 Using the Service Class 43.7 Creating the New Service 43.8 Modifying the User Interface 43.9 Running the Application 43.10 Creating a New Thread for Service Tasks 43.11 Summary
44.Android Local Bound Services – A Worked Example
44.1 Understanding Bound Services 44.2 Bound Service Interaction Options 44.3 An Android Studio Local Bound Service Example 44.4 Adding a Bound Service to the Project 44.5 Implementing the Binder 44.6 Binding the Client to the Service 44.7 Completing the Example 44.8 Testing the Application 44.9 Summary
45.Android Remote Bound Services – A Worked Example
45.1 Client to Remote Service Communication 45.2 Creating the Example Application 45.3 Designing the User Interface 45.4 Implementing the Remote Bound Service 45.5 Configuring a Remote Service in the Manifest File 45.6 Launching and Binding to the Remote Service 45.7 Sending a Message to the Remote Service 45.8 Summary
46.An Overview of Android SQLite Databases
46.1 Understanding Database Tables 46.2 Introducing Database Schema 46.3 Columns and Data Types 46.4 Database Rows 46.5 Introducing Primary Keys 46.6 What is SQLite? 46.7 Structured Query Language (SQL) 46.8 Trying SQLite on an Android Virtual Device (AVD) 46.9 Android SQLite Java Classes 46.9.1 Cursor 46.9.2 SQLiteDatabase 46.9.3 SQLiteOpenHelper 46.9.4 ContentValues 46.10 Summary
47.An Android TableLayout and TableRow Tutorial
47.1 The TableLayout and TableRow Layout Views 47.2 Creating the Database Project 47.3 Adding the TableLayout to the User Interface 47.4 Adding and Configuring the TableRows 47.5 Adding the Button Bar to the Layout 47.6 Adjusting the Layout Margins 47.7 Summary
48.An Android SQLite Database Tutorial
48.1 About the Database Example 48.2 Creating the Data Model 48.3 Implementing the Data Handler 48.3.1 The Add Handler Method 48.3.2 The Query Handler Method 48.3.3 The Delete Handler Method 48.4 Implementing the Activity Event Methods 48.5 Testing the Application 48.6 Summary
49.Understanding Android Content Providers
49.1 What is a Content Provider? 49.2 The Content Provider 49.2.1 onCreate() 49.2.2 query() 49.2.3 insert() 49.2.4 update() 49.2.5 delete() 49.2.6 getType() 49.3 The Content URI 49.4 The Content Resolver 49.5 The
50.Implementing an Android Content Provider in Android Studio
50.1 Copying the Database Project 50.2 Adding the Content Provider Package 50.3 Creating the Content Provider Class 50.4 Constructing the Authority and Content URI 50.5 Implementing URI Matching in the Content Provider 50.6 Implementing the Content Provider onCreate() Method 50.7 Implementing the Content Provider insert() Method 50.8 Implementing the Content Provider query() Method 50.9 Implementing the Content Provider update() Method 50.10 Implementing the Content Provider delete() Method 50.11 Declaring the Content Provider in the Manifest File
54.8 Handling the Intent Return 54.9 Testing the Application 54.10 Summary
55.Making Runtime Permission Requests in Android 6.
55.1 Understanding Normal and Dangerous Permissions 55.2 Creating the Permissions Example Project 55.3 Checking for a Permission 55.4 Requesting Permission at Runtime 55.5 Providing a Rationale for the Permission Request 55.6 Testing the Permissions App 55.7 Summary
56.Android Audio Recording and Playback using MediaPlayer and MediaRecorder
56.1 Playing Audio 56.2 Recording Audio and Video using the MediaRecorder Class 56.3 About the Example Project 56.4 Creating the AudioApp Project 56.5 Designing the User Interface 56.6 Checking for Microphone Availability 56.7 Performing the Activity Initialization 56.8 Implementing the recordAudio() Method 56.9 Implementing the stopAudio() Method 56.10 Implementing the playAudio() method 56.11 Configuring and Requesting Permissions 56.12 Testing the Application 56.13 Summary
57.Working with the Google Maps Android API in Android Studio
57.1 The Elements of the Google Maps Android API 57.2 Creating the Google Maps Project 57.3 Obtaining Your Developer Signature 57.4 Testing the Application 57.5 Understanding Geocoding and Reverse Geocoding 57.6 Adding a Map to an Application 57.7 Requesting Current Location Permission 57.8 Displaying the User’s Current Location 57.9 Changing the Map Type 57.10 Displaying Map Controls to the User 57.11 Handling Map Gesture Interaction 57.11.1 Map Zooming Gestures 57.11.2 Map Scrolling/Panning Gestures 57.11.3 Map Tilt Gestures 57.11.4 Map Rotation Gestures 57.12 Creating Map Markers 57.13 Controlling the Map Camera
57.14 Summary
58.Printing with the Android Printing Framework
58.1 The Android Printing Architecture 58.2 The Print Service Plugins 58.3 Google Cloud Print 58.4 Printing to Google Drive 58.5 Save as PDF 58.6 Printing from Android Devices 58.7 Options for Building Print Support into Android Apps 58.7.1 Image Printing 58.7.2 Creating and Printing HTML Content 58.7.3 Printing a Web Page 58.7.4 Printing a Custom Document 58.8 Summary
59.An Android HTML and Web Content Printing Example
59.1 Creating the HTML Printing Example Application 59.2 Printing Dynamic HTML Content 59.3 Creating the Web Page Printing Example 59.4 Removing the Floating Action Button 59.5 Designing the User Interface Layout 59.6 Loading the Web Page into the WebView 59.7 Adding the Print Menu Option 59.8 Summary
60.A Guide to Android Custom Document Printing
60.1 An Overview of Android Custom Document Printing 60.1.1 Custom Print Adapters 60.2 Preparing the Custom Document Printing Project 60.3 Creating the Custom Print Adapter 60.4 Implementing the onLayout() Callback Method 60.5 Implementing the onWrite() Callback Method 60.6 Checking a Page is in Range 60.7 Drawing the Content on the Page Canvas 60.8 Starting the Print Job 60.9 Testing the Application 60.10 Summary
61.Handling Different Android Devices and Displays
61.1 Handling Different Device Displays 61.2 Creating a Layout for each Display Size 61.3 Providing Different Images 61.4 Checking for Hardware Support 61.5 Providing Device Specific Application Binaries 61.6 Summary
64.3 The Top-level Gradle Build File 64.4 Module Level Gradle Build Files 64.5 Configuring Signing Settings in the Build File 64.6 Running Gradle Tasks from the Command-line 64.7 Summary
65. An Android Studio Gradle Build Variants Example
65.1 Creating the Build Variant Example Project 65.2 Extracting the Hello World String Resource 65.3 Adding the Build Flavors to the Module Build File 65.4 Adding the Flavors to the Project Structure 65.5 Adding Resource Files to the Flavors 65.6 Testing the Build Flavors 65.7 Build Variants and Class Files 65.8 Adding Packages to the Build Flavors 65.9 Customizing the Activity Classes 65.10 Summary
The goal of this book is to teach the skills necessary to develop Android based applications using the Android Studio Integrated Development Environment (IDE) and the Android 6 Software Development Kit (SDK).
Beginning with the basics, this book provides an outline of the steps necessary to set up an Android development and testing environment. An overview of Android Studio is included covering areas such as tool windows, the code editor and the Designer tool. An introduction to the architecture of Android is followed by an in-depth look at the design of Android applications and user interfaces using the Android Studio environment. More advanced topics such as database management, content providers and intents are also covered, as are touch screen handling, gesture recognition, camera access and the playback and recording of both video and audio. This edition of the book also covers printing, transitions and cloud-based file storage.
The concepts of material design are also covered in detail, including the use of floating action buttons, Snackbars, tabbed interfaces, card views, navigation drawers and collapsing toolbars.
In addition to covering general Android development techniques, the book also includes Google Play specific topics such as implementing maps using the Google Maps Android API, in-app billing and submitting apps to the Google Play Developer Console.
Chapters also cover advanced features of Android Studio such as Gradle build configuration and the implementation of build variants to target multiple Android device types from a single project code base.
Assuming you already have some Java programming experience, are ready to download Android Studio and the Android SDK, have access to a Windows, Mac or Linux system and ideas for some apps to develop, you are ready to get started.
The source code and Android Studio project files for the examples contained in this book are available for download at:
http://www.ebookfrenzy.com/retail/androidstudioA6/index.php
The steps to load a project from the code samples into Android Studio are as follows:
We want you to be satisfied with your purchase of this book. If you find any errors in the book, or have any comments, questions or concerns please contact us at [email protected].