Android Programming Slides
Android Programming Slides
1
Chinese Proverb
2
What you’ll learn
• Create your own professional quality
Android apps
• Deploy to the Google Play store
• Interview for a job anywhere in the world
3
Are there any course
requirements or
prerequisites?
• Modern laptop or computer
• Basics of XML, Java and Kotlin
4
Who this course is for:
• Beginners
• Web developers looking to get into mobile
• Programmers who haven't programmed in
Java
• Aspiring Android developers
• Anyone with a good idea and the drive to
create it
5
The real value...
• The most important thing you will get from
completing this course is the confidence to say
“I’m an Android Developer!”
• You’ll be able to interact with other students and
professionals in the Android community with
pride and self-assuredness.
• You’ll also become an independent learner, able
to discern where to go for information and how
to continue advancing your skills.
• No course is going to make you into an expert.
It’s up to you to challenge yourself and find your
path to making the apps you dream about. 6
Computer Program
• A set of instructions that enables
computer to process data
• Also called software
• Two types of computer programs
– Operating system programs - control
overall operations of computer
– Applications programs - perform tasks
required by users
7
Applications Programs
• Written by applications programmer
• May provide quick solution to one-time
problem
– Displaying average grade for set of exam
scores
• Or may be run on regularly scheduled
basis
– Program to print student transcripts each
semester
8
Program Languages
Machine language
• Only language computer understands
• All programs executed on computer
must be in machine language
• Machine language programs are difficult
to write
9
Program Languages
Symbolic language
English-like languages used to write
programs
• Easier than writing programs in machine
language
• Must be translated or compiled into
machine language to run on computer
10
1. Program Specifications
11
2. Design the Program
Program planning tools used to map out
structure and logic of program
• Flowcharts use block diagrams to
represent logic
• Pseudocode uses English-like statements
• Hierarchy charts (a.k.a. structure charts)
show relationships among sections of
program
12
3. Code and Enter Program
• Programmer writes and enters program
into computer
• Program written in symbolic language (like
Android,COBOL,C++,C#,Java etc)
• Called source program
13
4. Compile Source Program
Compiler is program that
• Checks source program for rule violations
• Translates source program into object
program
14
5. Test Program
• Test or debug program to ensure it
contains no errors
• Check for two types of errors
– Compile-Time Errors
– Execution Errors
15
6. Document the Program
• Documentation - formal set of procedures
and instructions to specify how to use
program
• Written for
– Those working with output
– Computer operators who run program
– Maintenance programmers who make
modifications to program
16
Projects:
Andriod App Development
• 1.Andriod Hacking for beginners
• 2.Andriod Studio Chat app similar to
whatsapp
• 3.Android Bluetooth chat app
17
Tools
• 1. Andriod Studio Emulator- Slow and
Sluggish [VM]
• 2. The real Android phone/ device -
Expensive
• 3. Genymotion-Fast
18
SDLC Framework
19
Problems To Be Solved
QUESTION 1
a) WRITE AN ANDROID PROGRAM TO COMPUTE THE FOLLOWING:
i) Sum of two numbers
ii) Quadratic equation
iii) Calculate your age
Question 2
a) What tools are used by the Systems Analyst/ Systems Developer at the Design phase in the traditional SDLC
approach
b) What Implementation Methods are used by the Systems Admin/ Systems Developer at the Implementation Stage in
the traditional SDLC approach
QUESTION 3
a) GR2 a) Features of Android and b) Applications of Android
b) GR1 Factors to consider in developing a Mobile Applications
20
SDLC Continued
• Waterfall model GR1
• Iterative model
• Spiral Model
• V Model GR2
• Rad Model
• Prototype
21
Android
Introduction
Basics of Android
• What is Android?
• Android is a mobile operating system based on the linux and
kernel.
• It's maintained by Google, and comes in a few different versions.
At the time of writing, mobile phones run a variant of version 2 of
Android, while most new tablets run a variant of version 3.
• Android's standard layout is to have a series of Home screens,
which can contain shortcuts to launch apps, or can contain widgets,
which are small programs that serve a single function, such as
controlling your music or displaying Facebook (Meta) updates.
History and version of Android
It is very interesting to know history and version of android.
1.5 Cupcake 3
1.6 Donut 4
2.1 Eclair 7
2.2 Froyo 8
2.3 Gingerbread 9 and 10
3.1 and 3.3 Honeycomb 12 and 13
4.0 Ice Cream Sandwitch 15
4.1, 4.2 and 4.3 Jelly Bean 16, 17 and 18
4.4
28
Android Version History
• V11 vs V12
• V11
https://www.youtube.com/watch?v=C7zN7Iq
C3sE
• V12
https://www.youtube.com/watch?v=RR1RtJ
NLvkA
Hidden codes and features
https://www.youtube.com/watch?v=lxpcJrhblj
29
M
Sources
• https://developer.android.com/
30
31
COURSE STRUCTURE: Part 1
• Definition
• Architecture
• Setting Android Dev
• Android SDK Manager and Packages
• Using Android
• AVD
• Creating the first Android application
• Package structure
• Gradle
• Running the application 32
Android core building block
• A component is simply a piece of code that has a well defined life cycle. e.g.-Activity,
Receiver, service etc.
• The core building blocks or fundamental components of android are activities,
views, intents, services, content providers, fragments and AndroidManifest.xml.
Activity
An activity is a class that represents a single screen. It is like a frame in AWT.
View
A view is the UI element such as button, label, text, field etc.
Anything that you see is a view.
Intent
intent is used to invoke components. It is mainly is used to:
Android core building block
• Start the service
• Launch an activity
• Display a web page
• Display a list of contacts
• Broadcast a message
• Dial a phone call etc.
Services
Service is background process that can run
for a long time.
Content provider
Content provider are used to share data between the applications.
Fragment
Fragment are like part of activity. An activity can display one or more
fragments on the screen at the same time.
Androidmanifest.xml
It contains information about activities, content provider, permissions
etc.
How to set up Android for eclipse IDE
There are following steps required for set up eclipse
IDE:
1. Install JDK
2. Download and install the eclipse for developing
android application
3. Download and install the android SDK
4. Install the ADT plugin for eclipse
5. Configure the ADT plugin
6. Create AVD
7. Create the hello android application
For more info visit: http://www.javatpoint.com/how-to-setup-android-for-eclipse-ide
How to make android apps
In this page we are creating the simple
example of android using eclipse IDE.
1.Create new android project
2.Write the message
3.Run the android application
Simple android example
Hello android example
1)Create a new android project
1. select File>New>Project…..
2. select android project and click next
3. Fill the details in this dialog box and
click finish
2) write the message
package com.example.helloandroid;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(textview);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
3) Run the android application
• right click on the project >run as..>android
application
Internal working of hello android example
Android UI widgets
There are many UI widgets with simple example such as button edittext,
autocompletetextview, togglebutton, datepiker, timepicker, progressbar etc.
• Working with buttons
Learn how to perform event handling on button click.
• Android toast
Displays information for the short duration of time.
• Custom toast
we can display the image on toast.
• Check box
application of simple food ordering.
• Toggle button
it has two states on/off.
• Alert dialog
Alert dialog containing the message with ok and cancel buttons.
• Spinner
display the multiple options but only selected at a time.
• Ratingbar
Ratingbar display rating bar.
• Datepicker
datepicker displays datepicker dialog that can be used to pick the
date.
• Timepicker
it can be used to pick the time.
Android lifecycle of Activity
Android fragments
• A fragment is an independent component which can be used by an
activity. Fragments represents multiple screen inside one activity.
• A fragment runs in the context of an activity, but has its own life
cycle and typically its own user interface. It is also possible to define
fragments without an user interface, i.e., headless fragments.
Advantages of using fragments
• Fragments make it easy to reuse components in different layouts,
e.g., you can build single-pane layouts for handsets (phones) and
multi-pane layouts for tablets.
• This is not limited to tablets; for example, you can use fragments
also to support different layout for landscape and portrait orientation
on a smartphone.
Java Programming
Introduction
Mthandazo Mhodie
In This Section:
• What is Java
• Application
• Types of Java Applications
• Java Platforms / Editions
• Difference between JDK, JRE, and JVM
What is Java
• Java is a programming language and a platform.
• Java is a high level, robust, object-oriented and secure
programming language.
• Java was developed by Sun Microsystems (which is now the
subsidiary of Oracle) in the year 1995.
• James Gosling is known as the father of Java.
• Before Java, its name was Oak.
• Since Oak was already a registered company, so James
Gosling and his team changed the Oak name to Java.
Platform:
Any hardware or software environment in which a program runs,
is known as a platform.
Since Java has a runtime environment (JRE) and API, it is called
a platform.
Application
According to Sun, 3 billion devices run Java. There are many
devices where Java is currently used.
Some of them are as follows:
• Desktop Applications such as acrobat reader, media player,
antivirus, etc.
• Web Applications such as irctc.co.in, javatpoint.com, etc.
• Enterprise Applications such as banking applications.
• Mobile
• Embedded System
• Smart Card
• Robotics
• Games, etc.
Types of Java Applications
There are mainly 4 types of applications that
can be created using Java programming:
1) Standalone Application
2) Web Application
3) Enterprise Application
4) Mobile Application
Standalone Application
• Standalone applications are also known as
desktop applications or window-based
applications.
• These are traditional software that we
need to install on every machine.
• Examples of standalone application are
Media player, antivirus, etc.
We use AWT and Swing are used in Java for
creating standalone applications.
Web Application
• An application that runs on the server side
and creates a dynamic page is called a
web application.
• Currently,
• Servlet, JSP, Struts, Spring, Hibernate, JS
F, etc. technologies are used for creating
web applications in Java.
Enterprise Application
• An application that is distributed in nature,
such as banking applications, etc. is called
enterprise application.
• It has advantages of the high-level
security, load balancing, and clustering.
• In Java, EJB is used for creating
enterprise applications.
Mobile Application
• An application which is created for mobile
devices is called a mobile application.
Currently, Android and Java ME are used
for creating mobile applications.
Java Platforms / Editions
There are 4 platforms or editions of Java:
1)Java SE (Java Standard Edition)
2)Java EE (Java Enterprise Edition)
3) Java ME (Java Micro Edition)
4) JavaFX
Java SE (Java Standard
Edition)
• It is a Java programming platform.
• It includes Java programming APIs such
as java.lang, java.io, java.net, java.util,
java.sql, java.math etc.
• It includes core topics like OOPs, String,
Regex, Exception, Inner classes,
Multithreading, I/O Stream, Networking,
AWT, Swing, Reflection, Collection, etc.
Java EE (Java Enterprise
Edition)
• It is an enterprise platform which is mainly
used to develop web and enterprise
applications.
• It is built on the top of the Java SE
platform.
• It includes topics like Servlet, JSP, Web
Services, EJB, JPA, etc.
Java ME (Java Micro Edition)
• It is a micro platform which is mainly used
to develop mobile applications.
JavaFX
• It is used to develop rich internet
applications. It uses a light-weight user
interface API.
Difference between JDK, JRE, and
JVM
JVM (Java Virtual Machine)
• is an abstract machine.
• It is called a virtual machine because it doesn't physically exist.
• It is a specification that provides a runtime environment in which Java
bytecode can be executed.
• It can also run those programs which are written in other languages and
compiled to Java bytecode.
• JVMs are available for many hardware and software platforms. JVM, JRE,
and JDK are platform dependent because the configuration of each OS is
different from each other.
• However, Java is platform independent.
The JVM performs the following main tasks:
• Loads code
• Verifies code
• Executes code
• Provides runtime environment
JRE
• JRE is an acronym for Java Runtime Environment. It is
also written as Java RTE.
• The Java Runtime Environment is a set of software
tools which are used for developing Java applications.
• It is used to provide the runtime environment.
• It is the implementation of JVM.
• It physically exists.
• It contains a set of libraries + other files that JVM
uses at runtime.
• The implementation of JVM is also actively released
by other companies besides Sun Micro Systems.
JDK
• JDK is an acronym for Java Development Kit.
• The Java Development Kit (JDK) is a software development
environment which is used to develop Java applications
and applets.
• It physically exists.
• It contains JRE + development tools.
• JDK is an implementation of any one of the below given Java
Platforms released by Oracle Corporation:
Standard Edition Java Platform
Enterprise Edition Java Platform
Micro Edition Java Platform
• The JDK contains a private Java Virtual Machine (JVM) and a few
other resources such as an interpreter/loader (java), a compiler
(javac), an archiver (jar), a documentation generator (Javadoc), etc.
to complete the development of a Java Application.
In this section
-Java Virtual Machine (JVM) & its
Architecture
-Software Code Compilation & Execution
process
-Why is Java both Interpreted and
Compiled Language?
-What is JIT
Why is Java slow?
Java Virtual Machine (JVM) & its
Architecture
• Java Virtual Machine (JVM) is a engine that
provides runtime environment to drive the
Java Code or applications.
• It converts Java bytecode into machines
language.
• JVM is a part of Java Run Environment
(JRE). In other programming languages, the
compiler produces machine code for a
particular system. However, Java compiler
produces code for a Virtual Machine known
as Java Virtual Machine.
Architecture meaning
• the complex or carefully designed
structure of something.
• the art or practice of designing and
constructing buildings.
how JVM works
• First, Java code is complied into bytecode.
This bytecode gets interpreted on different
machines
• Between host system and Java source,
Bytecode is an intermediary language.
• JVM is responsible for allocating memory
space.
Software Code Compilation &
Execution process
In order to write and execute a software program, you need the
following
1) Editor
To type your program into, a notepad could be used for this
2) Compiler
To convert your high language program into native machine code
3) Linker
To combine different program files reference in your main program
together.
4) Loader
To load the files from your secondary storage device like Hard Disk,
Flash Drive, CD into RAM for execution. The loading is automatically
done when you execute your code.
5) Execution
Actual execution of the code which is handled by your OS & processor.
Why is Java both Interpreted and
Compiled Language?
Programming languages are classified as
• Higher Level Language Ex. C++, Java
• Middle-Level Languages Ex. C
• Low-Level Language Ex Assembly
• finally the lowest level as the Machine Language.
Compiler
is a program which converts a program from one level of language to
another. Example conversion of C++ program into machine code.
• The java compiler converts high-level java code into bytecode
(which is also a type of machine code).
Interpreter is a program which converts a program at one level to
another programming language at the same level.
Example conversion of Java program into C++
What is JIT
Just-in-time compiler is the part of the Java
Virtual Machine (JVM).
It interprets part of the Byte Code that has
similar functionality at the same time.
Stopwatch App
119
COURSE STRUCTURE: Part 1
• Definition
• Architecture
• Setting Android Dev
• Android SDK Manager and Packages
• Using Android
• AVD
• Creating the first Android application
• Package structure
• Gradle
• Running the application 120
Definition
121
Architecture
122
Android SDK Manager and
Packages
123
Android Programming in images
• What is a Layout
• A blueprint or layout of the app once it is
designed
124
125
Layout
126
What is a View
• A class which help us utilize things like
Text View, Edit Text View etc
127
View
128
What is a Pixel?
• It is a physical point in a raster image
• A smallest addressable element in an all
points addressable display device…
• A physical quantity which we utilize to
measure distances on screen
• A unit to find a distance between two
points
• Use DP(Density Pixels) instead of PX
129
Pixel
130
Density Pixels
131
Density Pixels
132
Padding
• is the space inside of the element's border
133
Padding
134
Padding
135
Margin
• the space outside of the element's border
136
Layout of a Margin
137
Tasks
• Group 1: Matchwrap
• Group 2: Gravity
• Create a mini app such
that when a button is
clicked, an image
will appear
138
EVENT HANDLING
• are a useful way to collect data about a
user's interaction with interactive
components of Applications eg mouse
click, button click , touch etc
• Android framework maintains an event
queue as a FIFO*
139
Concepts related to Android
Event Management
1. Event Listeners
2. Event Listeners Registration
3. Event Handlers
140
1. Event Listeners
• an interface* in the View class that
contains a single callback method.
• These methods will be called by the
Android framework when the View to
which the listener has been registered is
triggered by user interaction with the item
in the UI.
141
2. Event Listeners
Registration
• process by which an Event Handler gets
registered with an Event Listener so that
the handler is called when the Event
Listener fires the event.
142
3. Event Handlers
• When an event happens and we have
registered an event listener for the event,
the event listener calls the Event Handlers,
which is the method that actually handles
the event.
143
Event listeners and Handlers
144
ANDROID STORAGE
• INTERNAL
• EXTERNAL
145
Useful links
• First things first
https://www.youtube.com/watch?v=kMI2jy-
WlGM
146