0% found this document useful (0 votes)
38 views146 pages

Android Programming Slides

Android developer course and study materials

Uploaded by

Mthandazo Mhodie
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
38 views146 pages

Android Programming Slides

Android developer course and study materials

Uploaded by

Mthandazo Mhodie
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 146

ANDROID PROGRAMMING

Facilitator: MTHANDAZO MHODIE

1
Chinese Proverb

"Tell me, I'll forget. Show me, I'll


remember. Involve me, I'll understand."

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

• Systems analysts, users and


programmers develop specifications
• Specifications include:
• Description of input and output data
• Step-by-step processing required to
convert input to output

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

Source program in Translated by Object program in


symbolic language compiler machine language

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

• Java and Kotlin

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

NB: For the above problems, Flowchat and Pseudocode.


num+=1

b) What are program planning tools used by systems Analysts


JSP, Nassi Shneiderman , Decision Structures , DT etc

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.

• Android was founded by Andy Rubin, Rich Minner, and Charris


White.
• The early intentions of the company were to develop an advanced
operating system for digital cameras, when it was realized that the
market for the devices was not large enough, and diverted their
efforts to producing a smart phone operating system to rival those of
Symbian and Windows Mobile.
• Initially android was developed for Television, video games, digital
cameras and electronics.
• Later android apps were shifted to mobiles.
• After 2 years Google bought the Android in 2005.
• In 2007 Google officially announced development of Android OS.
• Features are going to be added one version to another version.
Versions of Android
Versions of Android
Version Code name API

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

5.0 Lollipop -12L


Snowcone [Research] 19
KitKat
https://en.wikipedia.org/w
API Concepts
• What are they
• How do you consume them

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;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

TextView textview=new TextView(this);


textview.setText("Hello Android!");

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.

• In Java, the Just In Time Code generator


converts the bytecode into the native
machine code which are at the same
programming levels.
• Hence, Java is both compiled as well as
interpreted language.
Why is Java slow?
The two main reasons behind the slowness of Java
are
• Dynamic Linking: Unlike C, linking is done at run-
time, every time the program is run in Java.
• Run-time Interpreter: The conversion of byte
code into native machine code is done at run-time
in Java which furthers slows down the speed
• However, the latest version of Java has addressed
the performance bottlenecks to a great extent.
Summary:
• Full form of JVM is Java Virtual Machine. JVM is
the engine that drives the Java Code. It converts
Java bytecode into machines language.
• In JVM, Java code is compiled to bytecode. This
bytecode gets interpreted on different machines
• JIT stands for Just-in-time compiler. JIT is the part
of the Java Virtual Machine (JVM). It is used to
speed up the execution time
• In comparison to other compiler machines, Java
may be slow in execution.
In this Section
• Features of Java
• How to Download & Install Java JDK 17
(or later) in Windows
• Hello World
https://techvidvan.com/tutorials/features-of-java-programming-language/
Open Source
• Java since its birth, till today, is an open-
source product and it has all the public
access. programmers are free to post
entire source code for anyone to
download, copy, redistribute them, which
is usually part of the GPL (General Public
License,) the license that usually comes
with open-source software.
High Performance
• Java is an interpreted language, so it will
never be as fast as a compiled language
like C or C++. But, Java enables high
performance with the use of the just-in-
time compiler.
Multi-Threading
• This feature makes it possible to write a
program that can do many tasks
simultaneously.
• The benefit of multithreading is that it
utilizes the same memory and other
resources to execute multiple threads at
the same time, like While typing,
grammatical errors are checked along.
Secure
• When it comes to security, Java is always
the first choice. With java secure features
it enables us to develop virus-free, temper
free system.
• Java program always runs in Java runtime
environment with almost null interaction
with system OS, hence it is more secure.
Platform independent
• WORA- Unlike other programming languages
such as C, C++ etc which are compiled into
platform-specific machines. Java is
guaranteed to be Write-Once, Run-Anywhere
language. On compilation, Java program is
compiled into bytecode.
• This bytecode is platform-independent and
can be run on any machine, plus this
bytecode format also provides security.
• Any machine with Java Runtime Environment
can run Java Programs.
Portability
• The cross-platform feature enables the
Java code to be highly portable.
• Programmers can write code in windows
and execute the same code in Linux
Operating System.
Object-Oriented
• In java, everything is an object which has
some data and behaviour.
• Java can be easily extended as it is based
on Object Model.
Robust
• Java makes an effort to eliminate error-
prone codes by emphasizing mainly on
compile-time error checking and runtime
checking.
• But the main areas which Java improved
were Memory Management and
mishandled Exceptions by introducing
automatic Garbage Collector and
Exception Handling.
How to Download & Install Java
JDK 17( or later) in Windows
• This Java Development Kit(JDK) allows
you to code and run Java programs.
• It's possible that you install multiple JDK
versions on the same PC.
• But Its recommended that you install only
latest version.
steps to install Java in Windows
• Practical
Step 1
• Download the latest version of JDK
Step 2
1.Accept the Licence Agreement
2.Download the latest JDK either 32 or 64
Step 3
Step 4) Select the PATH for Java
installation and click next.
Step 5) Once installation is
complete click Close
How to set Environment
Variables in Java: Path and

Classpath
The PATH variable gives the location of executables
like javac, java etc.
• It is possible to run a program without specifying the
PATH but you will need to give full path of executable
like
C:\Program Files\Java\jdk-13.0.1\bin\javac A.java
instead of simple
javac A.java
• The CLASSPATH variable gives location of the Library
Files.
• Let's look into the steps to set the PATH and
CLASSPATH
How to?
• Step 1. Right Click on the My Computer and Select
the properties
Step 2) Click on advanced system
settings
Step 3) Click on Environment
Variables
Step 4) Click on new Button of
User variables
Step 5) Type PATH in the Variable
name.
Step 6) Copy the path of bin folder
which is installed in JDK folder.
Step 7) Paste Path of bin folder in
Variable value and click on OK
Button.
Note: In case you already have a PATH
variable created in your PC, edit the PATH
variable to
PATH = <JDK installation directory>\bin;%P
ATH%;
Here, %PATH% appends the existing path
variable to our new value
Step 8) You can follow a similar
process to set CLASSPATH.
Note: In case you java installation does not
work after installation, change classpath to
CLASSPATH = <JDK installation directory>\l
ib\tools.jar;
Step 9) Click on OK button
Step 10) Go to command prompt
and type javac commands.
• If you see a screen like below, Java is
installed.
Hello World
Before we get into the details, lets first start with the
coding and see how a basic Hello World program
in Java is coded.
1. public class HelloWorldDemo
2. {
3. public static void main(String[] args)
4. {
5. System.out.println( "Hello World!" );
6. System.exit( 0 ); //success
7. }
8. }
Syntax Analysis
Line 1: public class HelloWorldDemo {
• This line makes use of the keyword class for
declaring a new class called
HelloWorldDemo. Since Java is
an OOP Language, the entire class definition,
including all of its members must be
contained in between the opening curly brace
{ Line 2 and the closing curly brace} line 8
• Also, it is using the public keyword to
specify the accessibility of the class from
outside the package.
Line 2: public static void main(
String[] args ) {
• This line declares a method called main(String[]).
• It is called the main method and acts as the entry
point for the Java compiler to begin the execution
of the program.
• Whenever any program is executed in Java, the
main method is the first function to be invoked.
• Other functions in the application are then invoked
from the main method.
• In a standard Java application, one main method
is mandatory to trigger the execution.
• public: it is an access modifier specifies the visibility. It allows
JVM to execute the method from anywhere.
• static: It is a keyword which helps in making any class member
static. The main method is made static as there is no need for
creating an object to invoke the static methods in Java.
Thus, JVM can invoke it without having to create an object
which helps in saving the memory.
• void: It represents the return type of the method. Since the Java
main method doesn’t return any value its return type is declared
as void.
• main(): It is the name of the method that has been configured in
the JVM.
• String[]: It represents that the Java main method can accept a
single line argument of the type string array.
This is also known as java command line arguments.
Below I have listed down a number of valid java main method
signatures:
valid java main method
signatures
• public static void main(String[] args)
• public static void main(String []args)

• public static void main(String args[])


• public static void main(String… args)
• static public void main(String[] args)
• public static final void main(String[] args)
• final public static void main(String[] args)
Line 3: System.out.println( “Hello
World!” );
• System: It is a pre-defined class in java.lang
package which holds various useful methods
and variables.
• out: It is a static member field of type
PrintStream.
• println: It is a method of PrintStream
class and is used for printing the argument
that has been passed to the standard console
and a newline. You can also use print( )
method instead of println( ).
Line 4: System.exit( 0 );
• The java.lang.System.exit( ) method is
used to exit the current program by
terminating the currently executing Java
Virtual Machine.
• This method takes a status code as input
which is generally a non-zero value.
• It indicates in case any abnormal
termination occurs.
Exit (0) vs Exit (1) or (-1)
• exit(0): It is used to indicate successful
termination.
• exit(1) or exit(-1) or any non-zero value: It
is used to indicate unsuccessful
termination.
Exercise
• Write a Java program that prompts the
user to enter their names and age, and
then display it to the user
• Write a java program that prompts the
user to enter their Temperature in Degrees
Celsius and it converts it to Degrees
Fahrenheit
NB: 1 Celsius = 33.8 Degree Fahrenheit
Datatypes
• A data type is used to represent different
values which are stored in a variable.
• They are mainly classified into 4 different
aspects – Integer, Float, Character and
Boolean.
• You can refer to the below image to
understand the different data types with
respect to the memory allocated to them.
Primitive DataTypes
• data types are of 4 major types.
• The first data type is an Integer which stores a
numerical value.
• Now, if a numerical value contains the decimal
part, it will be referred to as a float Datatype.
• Next, if you wish to store a character, then the
third data type i.e char is used. In char, you can
store any alphabetical character as well as a
special character.
• The last data type is Boolean which stores only
‘true’ or ‘false’ value.
Control Structures
Week 2
Tasks:
Build Your First Android App in Java
https://developer.android.com/codelabs/build-your-first-android-app#3

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

• The size changes as per screen size


• Android calculates the size of density

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

You might also like