4B Mrs. S. Poornima

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

New Edition

MOBILE
APLICATION
DEVELOPMENT
(with Mobile Application Development Lab)

As per the University of Madras Syllabus


(Syllabus with effect from 2020-2021)
For VI Semester B.C.A Students

J. Mary Catherine
Assistant Professor and Head
Department of Computer Science

V. Nandhini
Assistant Professor
Department of Computer Science

S. Poornima
Assistant Professor
Department of Computer Applications
Chevalier T Thomas Elizabeth College for Women
Chennai.

With
Madras University
Part - A, B & C (Review Questions)

VR1 PUBLICATIONS
Empowerment Through Education
Title : Mobile Application Development
Author Name : J. Mary Catherine V. Nandhini S Poornima
Published by : VR1 Publications
Publisher’s Address : No. 23/25, Thambusamy Nagar, Thiruverkadu,
Chennai-77.
Printer’s Details : VR1 Prints, Chennai.
First Edition : Nov 2022
ISBN : 978-93-91332-51-8

© All Right Reserved by the publisher.

This book or part thereof should not be reproduced in any form without the
written permission of the Publisher and Authors.

Rs. 228/-

For copies please contact


VR1 PUBLICATIONS
#23/25, Thambusamy Nagar,
Thiruverkadu, Chennai - 77.
Cell; 98848 47857.

e-Mail: info@vr1publications.com.
Web: www.vr1publications.com.

Typesetting at : Goodwill Infotech, Chennai - 95.


PREFACE

Mobile Application Development using Android Studio is an interesting and


important programming skill to be learnt. This book aims to provide a holistic
view of Android programming with suitable illustrations. This describes the
key concepts of mobile application development and provides programming
examples with screenshots.
The contents of this book is organized into 11 chapters as per the sixth semester
syllabus of BCA of University of Madras.
Chapters 1 and 2 covers the basics of Android programming and provides
detailed information about installing and configuring Android Studio.
Chapters 3 and 4 provides a conceptual overview of Activities, Intents and
Fragments in Android. It also describes the creation and usage of notifications
and playing with display orientation.
Chapters 5, 6 and 7 focuses on creating the User Interface aesthetically using
tools like layouts and Views provided by Android.
Chapters 8 and 9 details the creation and sharing of data using SQLite and
Content Providers. It also describes the mechanism to create and receive
emails and SMSes. Sharing and manipulation of location data.
Chapters 10 and 11 focuses on creating custom web services and using various
web services from your application.
All labs exercises with code and screenshot is also provided.
We hope the reader will have thorough knowledge of Android programming
after going through this book.
Authors
ACKNOWLEDGEMENT

We would like to thank the Almighty for giving us this opportunity to write this
book. We are grateful to our family members for their support in our endeavour.
Our sincere thanks to the Management of Chevalier T Thomas Elizabeth
College of Women, Perambur, for their support and encouragement.
Authors
SYLLABUS
MOBILE APPLICATION DEVELOPMENT
Objectives:
G To make the student understand the basic concepts of mobile application
development, be aware of Characteristics of mobile applications, User-
interface design, basics of graphics and multimedia.
G To gain knowledge about testing and publishing of Android application.
Outcomes:
F To explain the basics of mobile application development
F Develop Android application with User interface, networking and animation.
F Use simulator tools to test and publish the application.
UNIT I: Mobile Application Development - Mobile Applications and Device
Platforms - Alternatives for Building Mobile Apps -Comparing Native vs.
Hybrid Applications -The Mobile Application Development Lifecycle-The
Mobile Application Front-End-The Mobile Application Back-End-Key Mobile
Application Services-What is Android-Android version history-Obtaining the
Required Tools- Launching Your First Android Application-Exploring the
IDE-Debugging Your Application-Publishing Your Application.
UNIT - II: Understanding Activities-Linking Activities Using Intents-
Fragments-Displaying Notifications- Understanding the Components
of a Screen-Adapting to Display Orientation-Managing Changes to
Screen Orientation- Utilizing the Action Bar-Creating the User Interface
Programmatically Listening for UI Notifications.
UNIT - III: Using Basic Views-Using Picker Views -Using List Views to
Display Long Lists-Understanding Specialized Fragments - Using Image
Views to Display Pictures -Using Menus with Views-Using WebView- Saving
and Loading User Preferences-Persisting Data to Files-Creating and Using
Databases.
UNIT - IV: Sharing Data in Android-Creating Your Own Content Providers
-Using the Content Provider- SMS Messaging -Sending Email-Displaying
Maps- Getting Location Data- Monitoring a Location.
UNIT - V: Consuming Web Services Using HTTP-Consuming JSON Services-
Creating Your Own Services - Binding Activities to Services -Understanding
Threading.
CONTENTS

Chapter 1 Basics of Mobile Computing 1.1 - 1.18


1.1 Introduction to Mobile Computing..................................................... 1.1
1.2 Mobile Applications and device Platform:......................................... 1.2
1.2.1 Platforms supported.............................................................. 1.2
1.2.2 Operating Systems:.............................................................. 1.4
1.3 Alternatives for Building Mobile Apps.............................................. 1.4
1.4 Defining Native vs. Web vs. Hybrid Apps.......................................... 1.5
1.4.1 Comparing Native vs. Hybrid Applications......................... 1.7
1.5 Mobile Application Development Lifecycle...................................... 1.7
1.6 Frontend vs. backend for mobile app development: .......................... 1.8
1.6.1 Frontend development.......................................................... 1.8
1.6.2 Frontend languages.............................................................. 1.9
1.6.3 Frontend frameworks......................................................... 1.10
1.6.4 Backend development........................................................ 1.11
1.6.5 Backend languages............................................................. 1.11
1.6.6 Difference Between The Mobile Application Front-End and .
Back-End ........................................................................... 1.13
1.7 Key Mobile Application Services..................................................... 1.14
Questions and Answers................................................................................ 1.17
Review Questions........................................................................................ 1.18

Chapter 2 Introduction to Android Studio 2.1 - 2.42


2.1 Introduction - Android Programming:................................................ 2.1
2.1.1 Architecture of Android....................................................... 2.1
2.2 History of Android.............................................................................. 2.4
2.3 Obtaining theRequired Tools.............................................................. 2.6
2.4 Creating and Managing Virtual Devices.......................................... 2.11
2.5 Launching Your First Android application....................................... 2.15
2.6 Exploring the IDE............................................................................. 2.17
2.7 Debugging Your Application............................................................ 2.24
2.8 Publishing your Application............................................................. 2.39
Questions and Answers................................................................................ 2.41
Review Questions........................................................................................ 2.41

Chapter 3 Basics of Android Programming 3.1 - 3.32


3.1 Building blocks of Android Application............................................. 3.1
3.1.1 Activity :............................................................................... 3.1
3.1.2 Intent and Intent Filters :...................................................... 3.2
3.1.3 Intent Receiver :................................................................... 3.2
3.1.4 Service :................................................................................ 3.2
3.1.5 Content Provider :................................................................ 3.3
3.2 AndroidManifest.xml file: ................................................................ 3.3
3.3 Understanding Activities.................................................................... 3.6
3.3.1 Creating an Activity............................................................. 3.7
3.3.2 Activity Life Cycle............................................................... 3.8
3.3.3 Applying Styles and Themes to an Activity....................... 3.12
3.3.4 Hiding the Activity Title..................................................... 3.13
3.3.5 Displaying a Dialog Window............................................. 3.13
3.3.6 Displaying a Progress Dialog............................................. 3.13
3.4 Linking Activities Using Intents....................................................... 3.13
3.4.1 Types of Intents.................................................................. 3.14
3.5 Fragments......................................................................................... 3.16
3.5.1 Fragment Lifecycle............................................................ 3.17
3.5.2 Fragment vs Activity.......................................................... 3.19
3.5.3 Creating a Fragment........................................................... 3.20
3.5.4 Add a fragment via XML................................................... 3.21
3.6 Displaying Notifications................................................................... 3.21
3.6.1 To create a notification:...................................................... 3.22
3.6.2 Set the notification’s tap action.......................................... 3.23
3.6.3 Show the notification.......................................................... 3.24
3.6.4 Add action buttons............................................................. 3.25
3.6.5 Add a direct reply action.................................................... 3.26
3.6.6 Add the reply button........................................................... 3.26
3.6.7 Retrieve user input from the reply...................................... 3.28
Questions and Answers................................................................................ 3.29
Review Questions........................................................................................ 3.31

Chapter 4 User Interface of Android 4.1 - 4.28


4.1 Introduction........................................................................................ 4.1
4.2 Understanding the Components of a Screen....................................... 4.1
4.2.1 View and ViewGroups.......................................................... 4.2
4.2.2 Types of layout..................................................................... 4.2
4.2.3 Attributes of Views and ViewGroups................................... 4.4
4.2.4 Units of Measurement.......................................................... 4.5
4.3 Adapting to Display Orientation......................................................... 4.5
4.3.1 Techniques for handling screen orientation.......................... 4.6
4.3.2 Example:............................................................................... 4.6
4.4 Managing Changes to Screen Orientation.......................................... 4.8
4.5 Persisting State changes during changes in configuration................ 4.12
4.6 Detecting orientation changes.......................................................... 4.13
4.7 Controlling the Orientation of the Activity....................................... 4.14
4.8 Utilizing the Action Bar.................................................................... 4.15
4.8.1 Retrieving an instance of ActionBar.................................. 4.16
4.8.2 Components of an ActionBar............................................. 4.16
4.8.3 Configuring an ActionBar ................................................. 4.17
4.8.4 Populating an ActionBar.................................................... 4.17
4.8.5 Adding Action Items to ActionBar..................................... 4.18
4.9 Creating the User Interface Programmatically ................................ 4.22
4.10 Listening for UI Notifications........................................................... 4.24
Questions and Answers................................................................................ 4.25
Review Questions........................................................................................ 4.27

Chapter 5 User Interface Design with Views and Specialized


Fragments 5.1 - 5.24
5.1 Introduction........................................................................................ 5.1
5.2 Android Views and ViewGroup ......................................................... 5.1
5.2.1 View..................................................................................... 5.1
5.2.2 ViewGroup........................................................................... 5.3
5.3 Using Basic Views.............................................................................. 5.4
5.3.1 TextView.............................................................................. 5.4
5.3.2 EditText................................................................................ 5.5
5.3.3 Buttonview........................................................................... 5.6
5.3.4 AutoCompleteTextView....................................................... 5.7
5.3.5 ProgressBar.......................................................................... 5.7
5.4 Using Picker Views............................................................................ 5.8
5.4.1 TimePicker........................................................................... 5.8
5.4.2 DatePicker ......................................................................... 5.11
5.5 Using List Views to Display Long Lists........................................... 5.13
5.5.1 ListView............................................................................. 5.13
5.5.2 SpinnerView....................................................................... 5.15
5.6 Understanding Specialized Fragments............................................. 5.16
5.6.1 ListFragment...................................................................... 5.16
5.6.2 DialogFragment.................................................................. 5.18
5.6.3 PreferenceFragment........................................................... 5.19
5.7 Common Attributes of Android Views............................................. 5.19
5.7.1 View Identifiers.................................................................. 5.19
5.7.2 View Height and Width...................................................... 5.19
5.7.3 Views Margin and Padding................................................ 5.20
5.7.4 View Gravity...................................................................... 5.20
5.7.5 Other commonView Attributes........................................... 5.21
Questions and Answers................................................................................ 5.22
Review Questions........................................................................................ 5.24

Chapter 6 Displaying Picture and Menus with Views and


Specialized Fragments 6.1 - 6.22
6.1 Introduction........................................................................................ 6.1
6.2 Using Image Views to Display Pictures............................................. 6.1
6.2.1 ImageView........................................................................... 6.1
6.2.2 ImageSwitcher...................................................................... 6.2
6.2.3 GridView.............................................................................. 6.5
6.3 Using Menus with Views.................................................................... 6.7
6.3.1 Menu Creation...................................................................... 6.8
6.3.2 Menu Attributes.................................................................... 6.9
6.3.3 Options Menu....................................................................... 6.9
6.3.4 Contextual Menu................................................................ 6.10
6.3.5 Popup Menu....................................................................... 6.12
6.4 Using WebView................................................................................ 6.12
6.4.1 Adding WebView to the application................................... 6.13
6.4.2 Methods of WebView In Android:..................................... 6.13
6.5 Persisting Data to Files..................................................................... 6.16
6.5.1 Saving to Internal Storage.................................................. 6.16
6.5.2 Saving to External Storage (SD Card)............................... 6.17
Questions and Answers................................................................................ 6.20
Review Questions........................................................................................ 6.22

Chapter 7 Data Persistence 7.1 - 7.16


7.1 Introduction........................................................................................ 7.1
7.2 Basics of Database.............................................................................. 7.2
7.3 Creatinga a Database.......................................................................... 7.5
7.4 Using the Database Programmatically............................................... 7.9
7.4.1 Adding Contacts................................................................... 7.9
7.4.2 Retrieving All the Contacts................................................ 7.10
7.4.3 Retrieving a Single Contact................................................ 7.11
7.4.4 Updating a Contact............................................................. 7.11
7.4.5 Deleting a Contact.............................................................. 7.12
7.5 Upgrading the Database.................................................................... 7.13
Questions and Answers................................................................................ 7.14
Review Questions........................................................................................ 7.15
Chapter 8 Content Providers 8.1 - 8.16
8.1 Introduction........................................................................................ 8.1
8.2 Sharing Data in Android..................................................................... 8.1
8.2.1 Sharing data between apps................................................... 8.2
8.3 Using a Content Provider................................................................... 8.6
8.3.1 Content Providers................................................................. 8.6
8.3.2 Various Parts of URI............................................................ 8.8
8.3.3 CursorLoader Class.............................................................. 8.8
8.4 Create Content Provider................................................................... 8.10
8.4.1 List of Methods ................................................................. 8.10
8.4.2 Predefined Query String Constants.................................... 8.11
Questions and Answers................................................................................ 8.13
Review Questions........................................................................................ 8.15

Chapter 9 Messaging using Android 9.1 - 9.44


9.1 Introduction........................................................................................ 9.1
9.2 SMS Messaging.................................................................................. 9.1
9.2.1 SMS Manager....................................................................... 9.1
9.3 Sending Email.................................................................................. 9.15
9.4 Displaying Maps............................................................................... 9.28
9.4.1 Android Google Map......................................................... 9.28
9.4.2 Types of Google Maps....................................................... 9.28
9.4.2 Methods of Google map..................................................... 9.29
9.4.3 Example of Google Map.................................................... 9.30
9.4.4 Steps for Getting the Google Maps API Key:................... .9.31
9.4.5 Callbacks in Google Maps................................................. 9.33
9.4.6 Google Map Zoom, Rotation............................................. 9.34
9.5 The Location Object......................................................................... 9.35
9.5.1 Get the Current Location.................................................... 9.37
9.5.2 Get the Updated Location.................................................. 9.38
9.5.3 Location Quality of Service............................................... 9.38
9.5.4 Geocoders........................................................................... 9.39
9.6 Monitoring a Location...................................................................... 9.40
Questions and Answers................................................................................ 9.42
Review Questions........................................................................................ 9.43

Chapter 10 Networking 10.1 - 10.18


10.1 Introduction...................................................................................... 10.1
10.2 Consuming Web Services Using HTTP ........................................... 10.1
10.2.1 Downloading Binary Data.................................................. 10.7
10.2.2 Downloading Text Content.............................................. 10.11
10.2.3 Accessing Web Services Using the GET Method ........... 10.14
10.3 Consuming JSON Services............................................................. 10.15
Questions and Answers.............................................................................. 10.16
Review Questions...................................................................................... 10.17

Chapter 11 Developing Android Services 11.1 - 11.24


11.1 Introduction...................................................................................... 11.1
11.2 Creating Your Own Services ........................................................... 11.1
11.2.1 Performing Long-Running Tasks in a Service .................. 11.4
11.2.2 Performing Repeated Tasks in a Service............................ 11.6
11.2.3 Executing Asynchronous Tasks on Separate .................. 11.10
11.2.4 Threads Using IntentService ........................................... 11.13
11.3 Binding Activities to Services ....................................................... 11.13
11.4 Understanding Threading ............................................................ .11.15
Questions and Answers............................................................................. .11.23
Review Questions...................................................................................... 11.23

University Lab Exercises........................................................ULE.1 - ULE.68

You might also like