Exam Code: AND - 801
Android Application Development
Andriod 8.x
Course Outline
• Covers a wide range of Android development topics.
• Provides essential lessons on various Android SDK libraries.
• Includes step-by-step lab exercises to build Android applications.
• Contains guides to build location-aware applications using GPS.
By Android ATC Team www.androidatc.com
AndroidTM Application Development
Lesson 1: Introduction to Kotlin
Kotlin History .......................................................................................................................... 1-2
Kotlin Advantages ................................................................................................................. 1-2
How Kotlin Programs Work? ............................................................................................... 1-2
Kotlin Software Prerequisites ............................................................................................ 1-3
Installing Java JDK and JRE.......................................................................................... 1-3
Installing Android Studio ..................................................................................................... 1-7
Creating Kotlin Project Using Android Studio ................................................................ 1-14
Creating a Kotlin Program ................................................................................................... 1-18
Running a Kotlin Program ................................................................................................... 1-19
Writing Comments ................................................................................................................ 1-21
Kotlin Variables ...................................................................................................................... 1-22
Kotlin Data Types................................................................................................................... 1-23
Input of Information to Kotlin Program ........................................................................... 1-33
Lesson 2: Control Flow Statements
Introduction ............................................................................................................................ 2-2
If Statement ............................................................................................................................ 2-2
If – Else Statement ............................................................................................................... 2-4
If Else and Logical Operators.............................................................................................. 2-6
When Statement and Expression ...................................................................................... 2-8
For Loops ................................................................................................................................. 2-9
While Loops ............................................................................................................................ 2-12
Do-while Loops ...................................................................................................................... 2-13
Jump Expressions ................................................................................................................. 2-14
Break Statement ............................................................................................................... 2-14
Continue Statement ......................................................................................................... 2-15
Return Statement ............................................................................................................. 2-15
Lesson 3: Functions & Object-Oriented Programming (OOP)
Functions ............................................................................................................................ 3-2
Function Structure ........................................................................................................... 3-2
Creating a Function .......................................................................................................... 3-3
Functions and Variable Scope ...................................................................................... 3-7
Object-Oriented Programming (OOP) .............................................................................. 3-8
Object ....................................................................................................................................... 3-9
Class ......................................................................................................................................... 3-9
Creating a Class ................................................................................................................ 3-9
2
AndroidTM Application Development AND-801
Providing Constructors for Your Classes ................................................................... 3-12
Class Inheritance .............................................................................................................. 3-13
Overloading Constructors .............................................................................................. 3-16
Overriding Properties ....................................................................................................... 3-18
Abstract Class ................................................................................................................... 3-20
Interface Class .................................................................................................................. 3-24
Generic Class ..................................................................................................................... 3-28
Enum Class ........................................................................................................................ 3-29
Class Variables.................................................................................................................. 3-30
Member Variables ............................................................................................................ 3-31
Kotlin Collections .................................................................................................................. 3-33
Class Hashmaps ............................................................................................................... 3-34
Class ArrayList .................................................................................................................. 3-37
Method mutableListOf .................................................................................................... 3-42
Lesson 4: Android Framework and Android Studio
Introduction ..............................................................................................................................
4-2
Android Platform Architecture ................................................................................................
4-2
Android Libraries ......................................................................................................................
4-4
Components of Android Application ...................................................................................... 4-4
Types of Android processes and their priorities ................................................................... 4-7
Android Application Development .......................................................................................... 4-8
Android SDK platform .........................................................................................................
4-8
Integrated Development Environment (IDE) ..................................................................... 4-8
Android Studio .....................................................................................................................
4-8
Gradle ...................................................................................................................................
4-10
Instant Run...........................................................................................................................
4-10
Lab 4: Creating Your First Application ................................................................................... 4-12
................................................................................. 4-13
Create an Android Virtual Device ....................................................................................... 4-18
Build a “Simple Calculator” Application ............................................................................ 4-24
Lesson 5: Creating User Interface UI
Introduction .............................................................................................................................. 5-2
Android Project Structure ....................................................................................................... 5-2
View ........................................................................................................................................... 5-7
Creating User Interface............................................................................................................ 5-13
Add a text box ................................................................................................................................ 5-13
Add an Image ................................................................................................................................. 5-15
Add Check Box ............................................................................................................................... 5-19
Add Radio Button .......................................................................................................................... 5-27
Lab 5: Creating a Pizza Order Application ............................................................................. 5-32
Create Your Application User Interface ................................................................................... 5-33
3
AndroidTM Application Development
...... .......................................................................... 5-40
Run Your Application.................................................................................................................... 5-41
Lesson 6: Android Layouts, Styles, Theme and Menus
Introduction .............................................................................................................................. 6-2
Views ........................................................................................................................................ 6-2
Layouts ...................................................................................................................................... 6-2
Constraint Layout ................................................................................................................ 6-4
Linear Layout ....................................................................................................................... 6-6
Relative Layout .................................................................................................................... 6-10
TableRow Layout ................................................................................................................. 6-15
Frame Layout ....................................................................................................................... 6-18
ScrowView Layout ............................................................................................................... 6-19
Android Styles and Themes .................................................................................................... 6-21
Android Styles...................................................................................................................... 6-22
Android Themes .................................................................................................................. 6-30
App Manifest ............................................................................................................................ 6-34
Adaptive Icons ..................................................................................................................... 6-36
Lab 6: Android Application Layouts, Styles, and Themes.................................................... 6-41
Create Your Application Layout ......................................................................................... 6-42
................................................................................... 6-42
..................................................................................................... 6-52
Lesson 7: Toasts, Activities, Navigations, and Views
Context Class............................................................................................................................ 7-2
Toast Class................................................................................................................................ 7-2
Positioning Your Toast ....................................................................................................... 7-8
What is an Activity? ................................................................................................................ 7-11
Activity Lifecycle ...................................................................................................................... 7-12
Managing the activity lifecycle .......................................................................................... 7-13
Android Intent ........................................................................................................................... 7-21
Navigating Between Activities ........................................................................................... 7-23
Passing Data Between Activities ....................................................................................... 7-29
Android Views ........................................................................................................................... 7-33
ListView ................................................................................................................................ 7-33
RecyclerView ....................................................................................................................... 7-41
..................................................................... 7-42
Adding a RecyclerView to an Activity................................................................................ 7-43
Creating a CardView ............................................................................................................ 7-45
Creating Your RecyclerView Adapter ................................................................................ 7-51
Adding Data to Your RecyclerView .................................................................................... 7-60
Running and Testing Your RecyclerView .......................................................................... 7-62
Adding Event Listeners to Each RecyclerView Row ........................................................ 7-63
4
AndroidTM Application Development AND-801
Introduction .............................................................................................................................. 8-2
Android Dialogs ........................................................................................................................ 8-2
Alert Dialog........................................................................................................................... 8-2
ProgressBar ......................................................................................................................... 8-9
SeekBar ................................................................................................................................ 8-18
Date Picker Dialog ............................................................................................................... 8-24
Time Picker Dialog .............................................................................................................. 8-28
Snackbar ................................................................................................................................... 8-30
Menus ........................................................................................................................................ 8-34
WebView .................................................................................................................................... 8-38
............................................................................................................... 8-42
....................................................................................... 8-44
........................................................................................................... 8-45
..................................... 8-52
.................................................................................... 8-53
Adding Android Menu. ........................................................................................................ 8-57
.......................................... 8-59
Lesson 9: Android Storage, SQLite and Content Providers
Android Storage Options .................................................................................................................. 9-2
Shared Preferences ........................................................................................................................... 9-2
Internal Storage .................................................................................................................................. 9-8
External Storage ................................................................................................................................. 9-15
Network Connection .......................................................................................................................... 9-18
SQLite Databases ............................................................................................................................... 9-18
SQLite Database in your application ........................................................................................ 9-18
SQLite Library................................................................................................................................. 9-18
Creating an adapter class for SQLite database ..................................................................... 9-19
Content Providers............................................................................................................................... 9-21
Creating a Content Provider ....................................................................................................... 9-23
Sync Adapters ..................................................................................................................................... 9-27
How SyncAdapters Work............................................................................................................. 9-27
ORMLite ................................................................................................................................................ 9-28
Choosing Internal or External Storage .......................................................................................... 9-29
Lab 9: SQLite Databases and Content Providers ....................................................................... 9-30
Creating an SQLite database...................................................................................................... 9-31
Querying an SQLite DB Table ..................................................................................................... 9-37
Creating a Content Provider ....................................................................................................... 9-44
Utilizing ORMLite Library ............................................................................................................ 9-59
5
AndroidTM Application Development
Lesson 10: Location-Aware Apps: Using GPS and Google Maps
Introduction ......................................................................................................................................... 10-2
What is GPS and how does it work? .............................................................................................. 10-2
Other Location Service Providers................................................................................................... 10-3
................................................................................................................. 10-4
Map Fragment................................................................................................................................ 10-5
Getting a Google API key............................................................................................................. 10-6
Adding a Google Map Marker..................................................................................................... 10-11
Methods to Capture a User’s Location .................................................................................... 10-16
Reverse Geolocation and Geocoder Class.............................................................................. 10-24
JSON and API ...................................................................................................................................... 10-28
Lab 10: Location-Aware Apps Using a GPS and Google Maps ............................................... 10-31
Creating an App Interface ........................................................................................................... 10-32
Getting a Google API key............................................................................................................. 10-34
.. .......................................................................... 10-37
.......................................................................................... 10-38
Capturing Users’ Location .......................................................................................................... 10-39
Finding the Nearest Restaurants to a User’s Current Location ......................................... 10-48