0% found this document useful (0 votes)
9 views9 pages

Untitled 2

Uploaded by

ogandofrancis16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views9 pages

Untitled 2

Uploaded by

ogandofrancis16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

10/28/2021

MOBILE APPLICATION DEVELOPMENT What is Android?


Introduction to Android • Android is a software stack
For for mobile devices that
Mobile Applications Development includes an operating
system, middleware and
(Android Platform Overview) key applications.

By Mbogo Njoroge

1 2

The ANDROID Evolution Stages OHA (Open Handset Alliance)


• A business alliance consisting of 47 companies to develop
open standards for mobile devices

** Exercise: Arrange the above android versions in a generational


chronology ; give the date of release and state the distinguishing
3 4
features of each version **

The Android Architecture Android S/W Stack – The Application Layer

• Android provides a set of core applications:


 Email Client
 SMS Program
 Calendar
 Maps
 Browser
 Contacts
 Etc

• All applications are written using the Java language.

5 6

1
10/28/2021

Android S/W Stack – The App Framework Layer The Features of the App Framework
Feature Role

View Used to build an application, including lists, grids,


System text boxes, buttons, and embedded web browser

Content Enabling applications to access data from other


Provider applications or to share their own data

Resource Providing access to non-code resources (localized


Manager strings, graphics, and layout files)

• Enabling and simplifying the reuse of components Notificatio Enabling all applications to display customer
n Manager alerts in the status bar
 Developers have full access to the same framework
APIs used by the core applications.
Activity Managing the lifecycle of applications and
 Users are allowed to replace components. Manager providing a common navigation backstack

7 8

Android S/W Stack – The Libraries Layer Android S/W Stack – The Runtime Section

• Core Libraries
 Providing most of the functionality available in the core libraries
of the Java language
• Including a set of C/C++ libraries used by components of  APIs
the Android system Data Structures
Utilities
• Exposed to developers through the Android application File Access
framework Network Access
Graphics
9
Etc 10

How the Dalvik Virtual Machine Works


Executing the Dalvik Executable (.dex) format
.dex format is optimized for minimal memory footprint.
Compilation

• The Dalvik Virtual Machine


Providing environment on which every Android
application runs
Each Android application runs in its own process, with its
own instance of the Dalvik VM.
Dalvik has been written such that a device can run Relying on the Linux Kernel for:
multiple VMs efficiently. Threading
Register-based virtual machine Low-level memory management
11 12

2
10/28/2021

Advantages of android
Android S/W Stack – The Linux Kernel Layer i. open platform and free. So many manufacturers that can design
a variety of software is loaded on the Android system.

ii. Android display system can be changed to horizontal or vertical,


making it easier for the user in finding an adequate picture you
want.

 Relying on Linux Kernel 2.6 for core system services iii. If you have a phone with Android consistently then you can
download and install several free programs for Android. You can
 Memory and Process Management see in the Android Market through applications based on
 Network Stack Android, Google Chrome.
 Driver Model
iv. With Google Chrome you can open many windows at once.
 Security
Many Android applications have been, until April 2011 has
 Providing an abstraction layer between the H/W and the rest of the S/W sta reached 250,000 applications for Android. With the support of
ck many applications, the user can change the screen display.
Android phones can also function as a router to share Internet.
13 14

Disadvantages of android
i. Android Linux-based system, so as to modify
Android, the user must know the commands on the Android Studio Application Fundamentals
Linux system, and should log on as administrator.

ii. Not only is the installation of Program, each phone


has a different way. The lack of compatibility all
users of Android phones, we must learn again if
Android phones to replace with other brands.

iii. Even to show any recovery mode, an Android


phone has a different way.

NB: So in conclusion, if you are a person who likes


to tinker with the phone, then you should not use For the love of Mobile Application Development with Android
mobile phones for Android.
15 16

Goal Applications
• Understand applications and their components • Written in Java or in Kotlin languages (it’s possible
• Concepts to consider involves: to write native code – will not cover that here)
– activity, • Good separation (and corresponding security)
– service,
from other applications:
– Each application runs in its own process
– broadcast receiver,
– Each process has its own separate VM
– content provider,
– Each application is assigned a unique Linux user ID –
– intent, by default files of that application are only visible to
– Android Manifest that application (can be explicitly exported)

17 18

3
10/28/2021

Application Components Activities


• Activities – visual user interface focused on a • Basic component of most applications
single thing a user can do • Most applications have several activities that
• Services – no visual interface – they run in the start each other as needed
background • Each is implemented as a subclass of the base
• Broadcast Receivers – receive and react to Activity class
broadcast announcements
• Content Providers – allow data exchange
between applications

19 20

Activities – The View Services


• Each activity has a default window to draw in • Does not have a visual interface
(although it may prompt for dialogs or
notifications) • Runs in the background indefinitely
• The content of the window is a view or a • Examples
group of views (derived from View or – Network Downloads
ViewGroup)
– Playing Music
• Example of views: buttons, text fields, scroll
bars, menu items, check boxes, etc. – TCP/UDP Server
• View(Group) made visible via • You can bind to a an existing service and
Activity.setContentView() method. control its operation
21 22

Broadcast Receivers Content Providers


• Receive and react to broadcast • Makes some of the application data available
announcements to other applications
• Extend the class BroadcastReceiver • It’s the only way to transfer data between
applications in Android (no shared files,
• Examples of broadcasts: shared memory, pipes, etc.)
– Low battery, power connected, shutdown, • Extends the class ContentProvider;
timezone changed, etc.
• Other applications use a ContentResolver
– Other applications can initiate broadcasts
object to access the data provided via a
ContentProvider

23 24

4
10/28/2021

Intents Shutting down components


• An intent is an Intent object with a message content. • Activities
• Activities, services and broadcast receivers are started by – Can terminate itself via finish();
intents. ContentProviders are started by ContentResolvers: – Can terminate other activities it started via finishActivity();
– An activity is started by Context.startActivity(Intent intent) or
Activity.startActivityForResult(Intent intent, int RequestCode)
• Services
– A service is started by Context.startService(Intent service) – Can terminate via stopSelf(); or Context.stopService();
– An application can initiate a broadcast by using an Intent in any of • Content Providers
Context.sendBroadcast(Intent intent), – Are only active when responding to ContentResolvers
Context.sendOrderedBroadcast(), and Context.sendStickyBroadcast()
• Broadcast Receivers
– Are only active when responding to broadcasts

25 26

Intent Filters
Android Manifest
• Its main purpose in life is to declare the components to the
system: • Declare Intents handled by the current application (in the
AndroidManifest):
<?xml version="1.0" encoding="utf-8"?>
<manifest . . . > <?xml version="1.0" encoding="utf-8"?>
<manifest . . . >
Shows in the
<application . . . > <application . . . >
<activity android:name="com.example.project.FreneticActivity"
Launcher and
is the main
<activity android:name= android:icon="@drawable/small_pic.png"
android:label="@string/freneticLabel" activity to
"com.example.project.FreneticActivity" ... >
<intent-filter . . . >
start
android:icon="@drawable/small_pic.png" <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
android:label="@string/freneticLabel" </intent-filter>
<intent-filter . . . >
... > <action android:name="com.example.project.BOUNCE" />
<data android:mimeType="image/jpeg" />
</activity> <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
... </activity>
...
</application> </application> Handles JPEG
</manifest> images in
</manifest> some way

27 28

Dalvik Java Virtual Machine (JVM) Android Applications Design


Java Source
Java Standard Edition
Java Source APPLICATION DESIGN: Elements, involves;
Code Code
Java Java
Compiler Compiler
I. GUI Definition
Java Byte Java Byte
Code Code
II. Events Management
Dex
Compiler
Stack-based Dalvik Byte III. Application Data Management
byte-code Code
Register-based IV. Background Operations
byte-code
Java Virtual
Machine
Dalvik Virtual
Machine
V. User Notifications
(JVM) (VM)

29 30

5
10/28/2021

Android Applications Design Android Components: Activities


An Activity corresponds to a single screen of
APPLICATION COMPONENTS include the the Application.
following;
An Application can be composed of multiples
 Activities screens (Activities).
 Intents
The Home Activity is shown when the user
 Services launches an application.
 Content Providers
Different activities can exhange information one
 Broadcast Receivers
with each other.
31 32

Android Components: Activities


 Each activity is composed by a list of graphics components.
 Some of these components (also called Views) can interact with the
user by handling events (e.g. Buttons). Example: The PROGRAMMATIC APPROACH

 Two ways to build the graphic interface:


1. DECLARATIVE APPROACH Button button=new Button (this);
2. PROGRAMMATIC APPROACH TextView text= new TextView();
text.setText(“Hello Mwana Android”);
Example: The DECLARATIVE APPROACH

< TextView android.text=@string/hello”


android:textcolor=@color/blue
android:layout_width=“fill_parent”
android:layout_height=“wrap_content” />
< Button android.id=“@+id/Button01”
android:textcolor=“@color/blue”
android:layout_width=“fill_parent”
android:layout_height=“wrap_content” />
33 34

Android Components: Activities


EXAMPLE
Android Components: Activities
- Build the application layout
Device 1 Device 2  Android applications typically use both the approaches!
HIGH screen pixel density LOW screen pixel density through XML files (like
HTML)
- Define two different XML DECLARATIVE APPROACH
layouts for two different
devices Define the Application layouts
- At runtime, Android detects XML Code and resources used by the
the current device Application (e.g. labels).
Java App Code configuration and loads the
appropriate resources for
PROGRAMMATIC APPROACH
the application
- No need to recompile!
Manages the events, and
- Just add a new XML file if handles the interaction with
you need to support a new
Java Code
XML Layout File XML Layout File the user.
Device 1 Device 2 device
35 36

6
10/28/2021

Android Components: Activities Android Components: Activities


 Views can generate events (caused by human  The Activity Manager is
interactions) that must be managed by the Android- responsible for creating,
developer. destroying, managing activities.
 Activities can be on different
states: starting, running,

TextEdit
Button

stopped, destroyed, paused.


 Only one activity can be on the
running state at a time.
ESEMPIO
 Activities are organized on a
public void onClick(View arg0) {
if (arg0 == Button) {
stack, and have an event-driven
// Manage Button events life cycle (details later …)
}
}

37 38

Android Components: Activities


 Main difference between Android-programming and Java -
programming:

Mobile devices have constrained resource


capabilities!

 Activity lifetime depends on users’ choice (i.e. change of


visibility) as well as on system contraints (i.e. memory
shortage).

 Developer must implement lifecycle methods to account


for state changes of each Activity …
39 40

Android Components: Activities Android Components: Intents


 Intents: asynchronous messages to activate core
public class MyApp extends Called when the Activity
is created the first time.
Android components (e.g. Activities).
Activity {
 Explicit Intent  The component (e.g. Activity1)
public void onCreate() { ... }
specifies the destination of the intent (e.g. Activity 2).
public void onPause() { ... }
Called when the Activity
public void onStop() { ... } is partially visible.
public void onDestroy(){ ... } LOGIN Welcome Marco!
marco
….
Called when the Activity
Activity1

Activity2

} is no longer visible. PASSWORD

*******

Login Intent
Called when the Activity Login
is dismissed.

41 42

7
10/28/2021

Android Components: Intents Android Components: Services


 Intents: asynchronous messages to activate core
Android components (e.g. Activities).  Services: like Activities, but run in background and do
not provide an user interface.
 Implicit Intent  The component (e.g. Activity1)  Used for non-interactive tasks (e.g. networking).
specifies the type of the intent (e.g. “View a video”).  Service life-time composed of 3 states:

Multiple choices
might be available

Activity2
to the user! Starting Destroyed

}
Activity1

Intent- onCreate()
View Filters onDestroy()
Activity2 onStart()
Running
Implicit Intent (on background)
43 44

Android Components: Content Providers Android Components: Broadcast Receivers


 Each Android application has its own private set of
 Publish/Subscribe
data (managed through files or through SQLite
paradigm
database).
 Content Providers: Standard interface to access and  Broadcast Receivers: An
share data among different applications. application can be
signaled of external
events.
insert()
APP  Notification types: Call
update() Content incoming, SMS delivery,
delete() Provider DB
Wifi network detected,
query()
e.g. Photo etc
Gallery

45 46

Android Components: Broadcast Receivers Android Components: Broadcast Receivers


BROADCAST RECEIVER example BROADCAST RECEIVER example

class WifiReceiver extends BroadcastReceiver {


public void onReceive(Context c, Intent intent) { public class WifiTester extends Activity {
String s = new StringBuilder(); WifiManager mainWifi;
wifiList = mainWifi.getScanResults(); WifiReceiver receiverWifi;
for(int i = 0; i < wifiList.size(); i++){ List<ScanResult> wifiList;
s.append(new Integer(i+1).toString() + "."); public void onCreate(Bundle savedInstanceState) {
s.append((wifiList.get(i)).toString()); …
s.append("\\n"); mainWifi = (WifiManager)
} getSystemService(Context.WIFI_SERVICE);
mainText.setText(sb); receiverWifi = new WifiReceiver();
} registerReceiver(receiverWifi, new
} IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
mainWifi.startScan();
}
47 48

8
10/28/2021

Android Components: System API Android Application Distribution


 Using the components described so far,
Android applications can then leverage the
system API …  Each Android application is
APK contained on a single APK file.
FILE
Some examples;  Java Byte-code (compiled for
Dalvik JVM)
 Telephony Manager data access (call, SMS, etc)
 Sensor management (GPS, accelerometer, etc)  Resources (e.g. images. videos,
 Network connectivity (Wifi, bluetooth, NFC, etc) XML layout files)
 Web surfing (HTTP client, WebView, etc) XML C
Files
 Storage management (files, SQLite db, etc) Libraries (optimal native C/C++
 …. code)

49 50

Android Application Distribution Android Application Security


 Android applications run with a distinct system
 Each application must be signed identity (Linux user ID and group ID), in an isolated
through a key before being way.
distributed.
 Applications must explicitly share resources and
data. They do this by declaring the permissions
 Applications can be distributed via they need for additional capabilities.
Web or via Stores.  Applications statically declare the permissions they
require.
 Android Play Store: application store  User must give his/her consensus during the
run by Google … but several other installation.
application stores are available (they ANDROIDMANIFEST.XML
are just normal applications).
<uses-permission
android:name=“android.permission.IACCESS_FINE_LOCATION" />

<uses-permission android:name=“android.permission.INTERNET"
51
/> 52

You might also like