This textbook is about learning Android and developing native apps using the Java programming language. It follows Java and Object-Oriented (OO) programmers’ experiences and expectations and thus enables them to easily map Android concepts to familiar ones.
Each chapter of the book is dedicated to one or more Android development topics and has one or more illustrating apps. The topics covered include activities and transitions between activities, Android user interfaces and widgets, activity layouts, Android debugging and testing, fragments, shared preferences, SQLite and firebase databases, XML and JSON processing, the content provider, services, message broadcasting, async task and threading, the media player, sensors, Android Google maps, etc.
The book is intended for introductory or advanced Android courses to be taught in one or two semesters at universities and colleges. It uses code samples and exercises extensively to explain and clarify Android coding and concepts. It is written for students and programmers who have no prior Android programming knowledge as well as those who already have some Android programming skills and are excited to study more advanced concepts or acquire a deeper knowledge and understanding of Android programming. All the apps in the book are native Android apps and do not need to use or include third-party technologies to run.
Author(s): Abdul-Rahman Mawlood-Yunis
Edition: 1
Publisher: Springer
Year: 2022
Language: English
Pages: 664
Tags: Android; Java; Object-Oriented Programming
Preface
Target Audience
Topics and Teaching Approach
Content and Explanation
Latest Code
Additional Resources for Users and Instructors
Convention Used in the Book
Acknowledgments
Contents
Chapter 1: Java Review
1.1 Introduction
1.2 Language Basics
1.2.1 Variables
1.2.2 Type of Variable
1.2.3 Java Primitive Data Types
1.2.3.1 Integers
1.2.3.2 Real Numbers
1.2.3.3 Char and Boolean
1.2.4 Default Variable Initializations
1.2.5 Typecasting
1.2.6 Type Assignment Example
1.2.7 Java String Class
1.2.7.1 String Concatenation
1.2.8 Java Operators
1.2.8.1 Associativity Rules
1.2.8.2 Shorthand Assignment Operators
1.2.9 Control Flow Statements
1.2.10 Arrays
1.2.11 ArrayList
1.2.12 Java Iterator Interface
1.2.13 For-Each Loop
1.3 Object-Oriented Programming Concepts in Java
1.3.1 Classes
1.3.2 Objects
1.3.2.1 Do It Yourself
1.3.3 Interfaces
1.3.3.1 Do It Yourself
1.3.4 Package
1.3.5 Inheritance
1.3.6 Inheritance Example
1.3.7 Polymorphism
1.3.7.1 Do It Yourself
1.3.8 Hiding Fields
1.3.9 Using the Keyword Super
1.3.10 Subclass Constructors
1.3.11 Using Preserved Keyword ``this´´
1.3.11.1 Using this with a Constructor
1.3.12 Java Exception Handling
1.3.12.1 The Try-Catch-Finally Block
1.3.13 Generic Types
1.3.13.1 A Simple Material Class
1.3.13.2 A Generic Version of the Material Class
1.3.14 Type Parameter Naming Conventions
1.3.14.1 Calling and Instantiating a Generic Type
1.3.14.2 Multiple Type Parameters
1.3.15 Autoboxing
1.3.16 Parameterized Types
1.3.17 Anonymous Classes
1.3.17.1 Declaring Anonymous Classes
1.3.17.2 Syntax of Anonymous Classes
1.3.18 Object Serialization
1.3.18.1 Serializable Interface
1.3.18.2 Serialize an Object
1.3.18.3 Deserialize an Object
1.3.18.4 Code Example
1.3.18.5 Example of Serializing an Object
1.3.18.6 Example of Deserializing an Object
1.3.19 Lambda Expressions
1.3.20 Variable Argument (Varargs)
1.3.20.1 Syntax of Varargs
1.3.20.2 Rules for Varargs
1.4 Chapter Summary
Further Reading
Chapter 2: Getting Started with Android
2.1 Introduction
2.2 Starting with Android
2.2.1 A Brief Android History
2.2.2 Android Is Open Source
2.2.3 Android Libraries
2.2.4 Android Popularity
2.2.5 Android Development Environment
2.2.6 Android Developer´s Skills
2.2.7 Model View Controller and App Development
2.2.8 Android´s Main Program
2.2.9 Java and Android
2.2.10 Why Use Java for Android?
2.2.11 Android and Linux
2.3 Download and Install Android Studio and Android SDK
2.3.1 Download the Android Studio
2.3.2 Install Android Studio
2.3.3 Update Android Files
2.3.4 Release Note
2.3.5 Android SDK
2.4 Create a New Android Project
2.4.1 Start New Project
2.4.2 Select an Activity Template
2.4.3 Fill in Application Requirement
2.4.4 Define SDK Requirements
2.4.5 Finish the Project Creation
2.5 Compiling and Running Android Apps
2.5.1 Running HelloWorld on Your Phone
2.5.2 Running the Android App in Android Studio
2.5.3 Issues Starting First App
2.5.4 Running HelloWorld on Emulator
2.5.5 Setting Up the Emulator
2.5.6 Do It Yourself
2.6 Compiling, Building, and Packaging Technologies
2.6.1 Compiling Android Code
2.6.1.1 Compiling Java Code
2.6.1.2 Minimizing and Obscuring Code
2.6.1.3 Turning .class into .dex Bytecode
2.6.1.4 Packaging DEX Files
2.6.2 Android App Bundle
2.6.3 Do It Yourself
2.6.4 Install Android Apps
2.6.5 Install APK from Online
2.6.6 Install APK from Files
2.6.7 From Dalvik to ART Runtime
2.6.8 Gradle Build
2.6.8.1 Gradle Build Files
2.6.8.2 Build Parameters
2.6.9 Software Versioning Using Local or Remote Repositories
2.6.9.1 Create a Git Repository
2.6.9.2 Integrating with GitHub or Bitbucket
2.7 Android Stack and Framework
2.7.1 Android Architecture
2.7.2 User and System Apps
2.7.3 Java API Framework
2.7.4 Native Libraries and Android Runtime
2.7.5 Hardware Abstraction Layer (HAL)
2.7.6 Linux Kernel
2.8 Chapter Summary
Further Reading
References
Chapter 3: Your First Android Application
3.1 Introduction
3.2 Android App Development
3.2.1 Early Android Development
3.2.2 Android Versions
3.2.3 Android Application Characteristic
3.2.4 Android Activity
3.2.4.1 Activity Constructors and Methods
3.2.5 R File
3.2.6 Android Context
3.2.7 Application Manifest Files
3.2.8 Opening Android Project in Android Studio
3.2.9 Cleaning Android Project Builds
3.3 Create Your First Mobile App
3.3.1 Your App Specification
3.3.2 Create Activity Layout
3.3.2.1 Adding an EditText Field to the Layout File
3.3.2.2 Add String to Resource File
3.3.2.3 Adding Components to the Layout File
3.3.3 Invoke Message on Activity
3.3.4 Intent Class
3.3.4.1 Explicit Intent
3.3.4.2 Implicit Intent
3.3.5 Using StartActivity
3.3.6 Create Second Activity
3.3.6.1 R.string and strings.xml File
3.3.7 Project Manifest Update
3.3.7.1 Intent-Filter and Launcher Screen
3.3.7.2 Setting Application Attributes
3.3.8 Running the App
3.3.9 Receiving Messages/Data from an Activity
3.3.10 Responding to the Messages from an Activity
3.4 Debugging Information
3.4.1 Debugging Using Log.d()
3.4.2 Using Logcat to View Log Messages
3.4.3 Do It Yourself
3.4.3.1 Exercise 1
3.4.3.2 Exercise 2
3.4.3.3 Exercise 3
3.5 Localize Your App and Resources
3.5.1 Create a Resource File for Second Language
3.5.2 Create Resource Entries for Languages Supported
3.5.3 Set Device Language
3.6 Chapter Summary
Further Reading
Chapter 4: Debugging and Testing Using Junit, Espresso, and Mockito Frameworks
4.1 Introduction
4.2 The Android Studio Debugger
4.2.1 Fault Handling Methods
4.2.2 Enable Debugger
4.2.3 Inspecting and Modifying Variable Values
4.2.4 Android Profiler
4.2.5 Device File Explorer
4.2.6 Android Debug Bridge (adb)
4.2.7 Do It Yourself
4.3 Toast and Snackbar Messages
4.3.1 Toast Messages
4.3.1.1 Creating Toast Messages
4.3.2 Snackbar Messages
4.3.2.1 Creating Snackbar Messages
4.3.3 Do It Yourself
4.3.4 The Log Class and Logcat Window
4.3.4.1 Logging Class Exception
4.3.4.2 Using adb with Log Messages
4.4 Android App Testing
4.4.1 Create a Test Class
4.4.2 Assert Methods
4.4.3 Hamcrest Assert Methods
4.4.4 Espresso Testing
4.4.5 Unit Testing
4.4.6 Unit Testing with Mockito
4.4.7 Code Coverage
4.4.8 Code Inspection and Refactoring
4.4.9 Reverse Engineering
4.5 Chapter Summary
Further Reading
References
Chapter 5: Activity Lifecycle and Passing Objects Between Screens Using Parcelable Interface
5.1 Introduction
5.2 Activity States
5.2.1 Activity and States
5.2.2 Transition Between States
5.2.2.1 Do It Yourself
5.2.3 The Launcher Activity
5.2.4 Implementing onCreate()
5.2.4.1 Understanding onCreate()
5.2.5 Bundle Class
5.2.5.1 Using Bundle Object with Intent
5.2.5.2 Bundle Object and Activity States
5.3 Understanding Activity Lifecycle
5.3.1 Understanding the onDestroy Method
5.3.2 Pausing and Resuming an Activity
5.3.3 Stopping and Restarting an Activity
5.3.4 Restoring Activity State
5.3.4.1 onSaveInstanceState()
5.3.5 Do It Yourself
5.4 Lifecycle Illustration App
5.4.1 Lifecycle Callback Methods
5.4.2 Callback Methods for the MainActivity
5.4.3 Callback Methods for the DisplayMessageActivity
5.4.4 Do It Yourself
5.4.5 Callback Method Implementations
5.4.6 Trigger the onPause() Method
5.5 Creating and Using Parcelable Objects
5.5.1 Passing User-Defined Objects Between Activities
5.5.2 LifeCycle with Parcelable Object
5.5.2.1 Parcelable Class Creation
5.5.3 Parcelable Example
5.5.3.1 Implement the Parcelable Interface
5.5.3.2 Declaring the Parcelable.Creator Interface Field
5.5.3.3 Implementing the describeContents Method
5.5.3.4 Implementing the writeToParcel Method
5.5.3.5 CREATOR Interface Constructs a Parcelable Object
5.5.3.6 Passing a Parcelable Object to Second Activity
5.5.3.7 Receiving a Parcelable Object from an Activity
5.5.3.8 Logging Callback Method Invocation
5.5.3.9 Testing LifecycleParcelable App
5.6 Chapter Summary
Further Reading
Chapter 6: User Interface Essential Classes, Layouts, Styles, Themes, and Dimensions
6.1 Introduction
6.2 Essential UI Classes and Properties
6.2.1 Android Project Structure
6.2.2 Views
6.2.2.1 View Listeners
6.2.2.2 View Properties
6.2.3 View Class Examples
6.2.3.1 EditText
6.2.3.2 TextView
6.2.4 Widget
6.2.5 ViewGroup
6.2.6 App Layout
6.3 Writing XML Layouts
6.3.1 Declare UI Elements in XML
6.3.2 Android Studio´s Layout Editor
6.3.3 Defining UI Programmatically
6.3.4 LinearLayout Java Class
6.3.5 LayoutParams Java Class
6.4 Details of the LayoutApplication Demo
6.4.1 MainActivity Layout
6.4.2 Activity with Linear Layout
6.4.3 Linear Layout XML File
6.4.4 Using Android Studio Design Option
6.4.5 strings.xml File
6.4.6 String Editor
6.4.7 String Resources
6.4.8 RelativeLayout
6.4.9 Other Layouts
6.4.9.1 FrameLayout
6.4.9.2 ConstraintLayout
6.4.9.3 Grid and Table Layouts
6.4.10 Parent-Child Relationship Between Activities
6.4.10.1 Do It Yourself
6.5 Styles, Themes, and Dimension
6.5.1 Defining a Style File
6.5.2 Applying Styles
6.5.3 Defining the App´s Theme
6.5.4 The Difference Between a Theme and Style
6.5.5 Padding and Margin View Properties
6.5.6 Gravity and Weight View Properties
6.5.6.1 Do It Yourself
6.5.7 Dimensions of a Phone and UI
6.5.7.1 Do It Yourself
6.6 Chapter Summary
Further Reading
Chapter 7: ListView, ScrollList, Date and Time Pickers, and RecyclerView
7.1 Introduction
7.2 List Views
7.2.1 Adapter and ArrayAdapter Classes
7.2.1.1 ArrayAdapter Classes
7.2.2 ListView and ListActivity
7.2.2.1 Define a Layout for the Items on the List
7.2.2.2 Create the ListActivity Class
7.2.2.3 Define Data
7.2.2.4 Select an Adapter Class
7.2.2.5 Create an ArrayAdapter Class
7.2.2.6 Assign the Adapter to List View
7.2.2.7 Assign a Listener to the List View
7.2.2.8 Do It Yourself
7.3 Date and Time Pickers
7.3.1 Date and Time Pickers
7.3.2 Set Date Using the DatePicker
7.3.2.1 The DatePickerDialog Class
7.3.2.2 The OnDateSetListener Interface
7.3.3 Set Time Using the TimePicker
7.3.3.1 TimePickerDialog Class
7.3.3.2 OnTimeSetListener Interface
7.3.3.3 The Calendar Class
7.3.4 Pickers and Anonymous Classes
7.4 Scroll Views
7.4.1 The ScrollView Class
7.4.2 Top-Level XML Element for a Scroll View
7.4.3 Scroll View Activity
7.5 RecyclerView
7.5.1 Using RecyclerView, Adapter, and ViewHolder Classes
7.5.1.1 Create Objects for Rows in the List
7.5.1.2 A Layout File for Rows in the List
7.5.1.3 RecyclerViewActivity Layout
7.5.1.4 Data Model
7.5.1.5 RecyclerView.Adapter Class
7.5.2 RecyclerViewActivity
7.5.3 Adapter and ViewHolder
7.5.3.1 ArrayAdapter
7.5.3.2 onCreateViewHolder
7.5.3.3 LayoutInflater and Adapter Class
7.5.3.4 The Inflate Method
7.5.3.5 ViewHolder
7.5.3.6 onBindViewHolder
7.5.3.7 getItemCount()
7.5.3.8 Recycler View Class Diagram
7.5.4 Using Recycler View with Older SDKs
7.6 Chapter Summary
Further Reading
Chapter 8: Toolbar, Menu, Dialog Boxes, Shared Preferences, Implicit Intent, and Directory Structure
8.1 Introduction
8.2 More User Interface
8.2.1 ActionBar
8.2.2 Toolbar
8.2.3 Add androidx.appcompat Library to the Project
8.2.3.1 Add the Support Library to the build.gradle
8.2.3.2 Import Toolbar
8.2.4 Extending AppCompatActivity
8.2.5 Specify a Theme with NO ActionBar
8.2.6 Adding Toolbar Element to the Layout
8.2.7 Menu Interface
8.2.8 Options Menu and App Bar
8.2.8.1 Menu Inflater and Click Handling
8.2.8.2 Define Menu XML File
8.2.8.3 Menu Item Properties
8.2.8.4 orderInCategory Attribute
8.2.8.5 Methods from the Activity Class for Menu
8.2.8.5.1 onCreateOptionsMenu(Menu menu)
8.2.8.5.2 onMenuItemSelected(MenuItem menuItem)
8.2.8.6 Toolbar Summary
8.2.9 Context Menu
8.2.10 Popup Menu
8.3 Dialog Boxes and the Camera App
8.3.1 Dialog Boxes
8.3.2 Custom Dialog Boxes
8.3.3 Access a Phone´s Default Camera App
8.3.4 Starting Activities for Results
8.3.4.1 Do It Yourself
8.3.5 Activity Result in AndroidX
8.4 Saving Data with SharedPreferences
8.4.1 SharedPreferences Interface
8.4.1.1 SharedPreferences Creation and Use
8.4.1.2 Editor Interface
8.4.1.3 Commit Method
8.4.1.4 SharedPreferences Reading Methods
8.4.1.5 Changes to Our Demo App
8.4.1.6 Running and Testing the Demo App
8.4.2 Layout for Shared Preferences Activity
8.4.3 How SharedPreferencesActivity Code Works
8.4.3.1 OnCreate()
8.4.3.2 loadUserData()
8.4.3.3 Update SharedPreferences Content
8.4.3.4 Saving Data in a Shared Preferences XML File
8.4.3.5 Do it Yourself
8.5 Directory Structure and Saving Data in Files
8.5.1 Internal Storage Location
8.5.2 External Storage Location
8.5.3 Standard Public Directories for Data/Files
8.5.3.1 Access Internal Files
8.5.3.2 Accessing Files You Create
8.5.4 Android File IO Classes and Methods
8.5.5 Accessing External Storage Files
8.5.6 Permission to Access External Directory
8.5.7 Examples Using External Methods
8.5.7.1 getExternalFilesDir
8.5.7.2 getExternalStorageDirectory
8.5.8 Environment Class and getExternalStoragePublicDirectory
8.5.8.1 Environment.DIRECTORY_DCIM
8.5.8.2 Environment.getExternalStorageDirectory
8.5.8.3 Environment.DIRECTORY_DOWNLOADS
8.5.8.4 Environment.getRootDirectory
8.5.9 Locate Apps on Emulator File System
8.5.9.1 Do It Yourself
8.6 Chapter Summary
Further Reading
Chapter 9: Fragments, Dynamic Binding, Inheritance, Pinching, and Screen Swiping
9.1 Introduction
9.2 The Fragment Basics
9.2.1 Fragment Uses
9.2.2 Why Using Fragments
9.2.3 Fragment Lifecycle
9.2.3.1 Activity Lifecycle Impacts on Fragments
9.2.3.2 Fragments Extra Lifecycle Callbacks
9.2.3.3 Overriding Fragment Callback Methods
9.3 Creating an App with the Fragments
9.3.1 Create a Fragment
9.3.2 One Activity and Multiple Layouts
9.3.3 Detecting Device Size and Orientation
9.3.4 Fragment Development Steps in Details
9.3.4.1 Extending Fragment Class
9.3.4.2 Implement the onCreateView Method
9.3.4.3 The onCreateView Method Signature
9.3.4.4 Implement Other Methods
9.3.4.5 Using FragmentManager and FragmentTransaction Classes
9.3.4.6 Creating Layout Files
9.3.4.7 Creating Layout and Fragment Classes
9.3.4.8 Attaching Proper Layout to the Device View
9.3.4.9 Communication Between Fragment and Its Host Activity
9.3.5 The MainActivity Class and Demo App Demonstration
9.3.5.1 Do It Yourself
9.3.6 Inserting Fragments in the Activity
9.3.6.1 Dynamic Binding
9.3.6.2 Static Binding
9.3.7 Fragment Static Binding Example
9.4 Inheritance in Android
9.4.1 Create a Base Activity
9.4.1.1 onViewReady
9.4.1.2 getContentView
9.4.1.3 Toolbar
9.4.2 Layout for the BaseActivity
9.4.3 No onCreate() Method for Child Class
9.4.4 Layout Reuse
9.5 Density-Independent Pixel and Screen Sizes
9.5.1 Naming Scheme
9.5.2 Supporting Different Screen Sizes
9.5.2.1 Create Directory Using Android Studio
9.5.3 Density-Independent Pixel (dp)
9.5.3.1 Various Drawable Sizes
9.6 Pinching and Screen Swiping
9.6.1 Pinch to Zoom Image
9.6.1.1 Do It Yourself
9.6.2 Swiping Gesture
9.6.3 Swiping Gesture App
9.6.3.1 Do It Yourself
9.7 Chapter Summary
Further Reading
Chapter 10: Parsing Remote XML and JSON Files, Using HTTPUrlConnection, XmlPullParser, and AsyncTask
10.1 Introduction
10.2 Parsing Remote and Local XML Files
10.2.1 XML Parser Review
10.2.2 Push Parsing
10.2.2.1 Push Parser Iterator
10.2.3 Pull Parser
10.2.4 Remote XML Parsing
10.2.4.1 Input File
10.2.4.2 Parser Instantiation Using XmlPullParser Class
10.2.4.3 Connecting to Server Using HTTPUrlConnection
10.2.5 Parsing Events
10.2.5.1 Parsing Loop
10.2.6 Reading Image from Local File
10.2.7 Retrieving Image from Remote Server
10.2.8 An Example of Reading Image File
10.2.9 A Demo App
10.2.9.1 Spinner Initialization and Handling
10.2.9.2 Predefined Layouts
10.2.10 Parsing Local XML File
10.2.11 Asset Folder
10.3 AsyncTask and Thread Handling
10.3.1 AsyncTask Class
10.3.2 Using AsyncTask Class
10.3.3 AsyncTask and Varargs Type
10.3.4 Input, Progress, and Result Parameters to AsyncTask
10.3.5 AsyncTask Execute Methods
10.3.6 AsyncTask Method Sequence Calls
10.4 App Implementation Details
10.4.1 WeatherForecast Class
10.4.1.1 Weather URL
10.4.1.2 doInBackground()
10.4.1.3 onProgressUpdate( )
10.4.1.4 onPostExecute( )
10.4.2 Complete Code for Weather Network App Activity
10.4.2.1 Do It Yourself
10.4.3 Parsing JSON Files
10.4.4 Other XML Feeds
10.5 An App for Information on Covid-19
10.5.1 Covid-19 App Development Steps
10.5.2 Data Extraction and Conversion
10.5.3 Testing and Production Development Environments
10.5.4 Covid-19 Source Code and Class Structure
10.6 Chapter Summary
Further Reading
Chapter 11: Android SQLite, Firebase, and Room Databases
11.1 Introduction
11.2 The Android SQLite Database
11.2.1 SQLiteOpenHelper Class
11.2.2 SQLiteDatabase Class
11.2.3 Overriding Methods of the SQLiteOpenHelper Class
11.2.4 The Class Constructor Method
11.2.5 The onCreate() Method
11.2.5.1 Create Table in Database
11.2.6 onUpgrade Method
11.2.7 onDowngrade Method
11.2.8 onOpen() Method
11.2.9 Read and Read/Write Access
11.2.10 The execSQL Method from SQLiteDatabase Class
11.3 Content Values and Cursor Objects
11.3.1 Content Values and Insert Method
11.3.1.1 Do It Yourself
11.3.2 Cursor
11.3.3 Query Data
11.3.4 rawQuery
11.3.5 More Methods of the SQLiteDatabase Class
11.3.5.1 Replace Method
11.3.5.2 Update Method
11.3.5.3 Delete Method
11.4 DatabaseDemo Project
11.4.1 The Data Component
11.4.2 The Middle Component
11.4.3 The View Component
11.4.4 Test Your Database Using SQLiteBrowser
11.4.4.1 Locate Your App Database
11.4.4.2 Open Your Database with SQLiteBrowser
11.4.4.3 Test Your Database with SQLiteBrowser
11.4.5 Use SQLiteBrowser for Database Design
11.4.5.1 Sqlite3 Database Tool
11.4.5.2 Do It Yourself
11.4.6 Android Database Inspector
11.5 Realtime Firebase Database
11.5.1 Firebase and JSON Tree File
11.5.2 Firebase Account and Project Setup
11.5.3 Register Your Project Using the Firebase Console
11.5.4 Adding Dependency to Your Project
11.5.5 Connecting to Database
11.5.6 Inserting Data into Database
11.5.7 Retrieving Data from Database
11.5.8 Deleting Data from Database
11.5.9 Query Data from Database
11.5.10 DataSnapshot and Query Classes
11.5.11 ChildEventListener Interface
11.5.12 Querying Firebase Database Using User-Defined Classes
11.5.13 Querying Firebase Database Example
11.6 Other Data Storage Options
11.6.1 Room Database
11.6.1.1 Entity Class
11.6.1.2 DAO Interface
11.6.1.3 Database Class
11.6.1.4 App Room Database Class
11.6.1.5 Do It Yourself
11.6.2 Content Provider
11.6.3 Internal and External Storage
11.6.3.1 Device File System
11.6.3.2 SD Card, USB Storage, and Standard Public Directories
11.7 Chapter Summary
Further Reading
References
Chapter 12: Content Provider, Service, Message Broadcasting, and Multimedia Player
12.1 Introduction
12.2 Content Provider Component
12.2.1 Content Provider
12.2.2 Creating a Content Provider
12.2.2.1 Designing a URI
12.2.2.2 onCreate Method Implementation
12.2.2.3 Query Method Implementation
12.2.2.4 Insert Method Implementation
12.2.2.5 Update Method Implementation
12.2.2.6 Delete Method Implementation
12.2.2.7 getType Method Implementation
12.2.2.8 ContentProvider Code Example
12.2.3 Provider in Manifest File
12.2.4 Run and Test Content Provider
12.2.4.1 Do It Yourself
12.2.5 Content Provider Client
12.2.5.1 Do It Yourself
12.3 Media Content Streaming Apps
12.4 Android Service
12.4.1 Service
12.4.2 Communication with Service
12.4.3 Services Lifecycle
12.4.4 Creating Service
12.4.4.1 OnStartCommand()
12.4.4.2 Service and Threads
12.4.4.3 Starting Service with the Intent
12.4.4.3.1 Service and Intent-Filter
12.4.4.3.2 Intent-Filter and Activity
12.4.5 Service Binding
12.4.5.1 Allow Apps to Bind to Service
12.4.5.2 Prohibit Apps to Bind to Service
12.4.6 OnCreate() Method for Service
12.4.7 OnDestroy() Method
12.4.8 Stopping Service
12.4.9 Android Rules to End Service
12.4.10 Declaring a Service in the Manifest
12.4.11 Intent Service
12.4.12 Service Summary
12.4.13 Do It Yourself
12.5 Message Broadcasting in Android
12.5.1 Android Message Broadcasting Types
12.5.2 BroadcastReceiver Class
12.5.2.1 Create a BroadcastReceiver Object
12.5.2.2 BroadcastReceiver Registration
12.5.2.3 Using the sendBroadcast Method
12.5.2.4 Receiving Broadcasted Message
12.5.3 Do It Yourself
12.6 Android MediaPlayer for Streaming Radio Stations
12.6.1 App Structure
12.6.2 Android Media Player
12.6.3 Power Manager and WakeLock
12.6.4 WifiLock
12.6.5 Other App Components
12.6.6 Stopping and Restarting Service
12.6.7 The New Restriction on Background Service
12.6.8 Do It Yourself
12.7 Remote and Local Video Playback
12.7.1 Playback Video Using Implicit Intent and URL
12.7.2 Playback Live Streaming Video Using URL and VideoView
12.7.3 Playback Embedded Video in Your App
12.7.4 Playback Video Outside Your App Directory
12.8 Chapter Summary
Further Reading
Chapter 13: Sensors, Location-Based Service, and Google Maps
13.1 Introduction
13.2 Android Sensor
13.2.1 Accelerometer Sensor
13.2.2 Accelerometer App
13.2.3 Using Accelerometer
13.2.3.1 Sensor Event Listener Implementation
13.2.3.2 Getting Sensor Service and Sensor Manager Objects
13.2.3.3 Display Accelerometer Readings
13.2.3.4 Calculating Acceleration Force
13.2.3.5 Listener Registration
13.2.3.6 Unregister Listening
13.2.4 Get List of Sensors
13.2.5 Do It Yourself
13.3 Location-Based Services
13.3.1 Demo App Interface
13.3.2 Location Service APIs
13.3.3 App Development Steps
13.3.3.1 Permission
13.3.3.2 Obtaining Location Manager
13.3.3.3 Obtaining Location Providers
13.3.3.4 Geocoder
13.3.3.5 Register LocationListener
13.3.4 App Implementation Details
13.3.4.1 Check and Request Permission
13.3.4.2 Location Manager Setup
13.3.4.3 Specify Location Provider
13.3.4.4 Find Your Last Location
13.3.4.5 Refresh Current Location
13.3.4.6 Do It Yourself
13.3.4.7 Use Geocoding
13.3.5 Revising Weather App
13.3.6 Do It Yourself
13.4 Use Google Maps in Your App
13.4.1 Create a Google Maps Project
13.4.2 Obtaining App Key
13.4.3 Update Manifest File
13.4.4 Google Maps API
13.4.5 GoogleMap Class
13.4.6 OnMapReadyCallback Interface
13.4.7 SupportMapFragment Class
13.4.8 Map Fragment Layout Example
13.4.9 MapView
13.4.10 UiSettings
13.4.11 Configure Initial State
13.4.12 Setting Map Initial State Programmatically
13.4.13 Covid App Revised
13.5 Chapter Summary
Further Reading
References
Index