Professional Documents
Culture Documents
com
2
This watermark does not appear in the registered version - http://www.clicktoconvert.com
Steps
§ Link JNI with native code, and application logic with JNI
4
This watermark does not appear in the registered version - http://www.clicktoconvert.com
5
This watermark does not appear in the registered version - http://www.clicktoconvert.com
Application apk
JNI Code
Shared library
Native Code
Figure-1: Application architecture without jar file, and placing of various components w.r.t. Android architecture
6
This watermark does not appear in the registered version - http://www.clicktoconvert.com
Application apk
JNI Code
Shared library
Native Code
Figure-2: Application architecture with jar file, and placing of various components w.r.t. Android architecture
7
This watermark does not appear in the registered version - http://www.clicktoconvert.com
Application UI Layout
8
This watermark does not appear in the registered version - http://www.clicktoconvert.com
UI Layout
Title
High-level
Components
10
This watermark does not appear in the registered version - http://www.clicktoconvert.com
UI Coding
simple.xml complex.xml
11
This watermark does not appear in the registered version - http://www.clicktoconvert.com
12
This watermark does not appear in the registered version - http://www.clicktoconvert.com
Native Interface
13
This watermark does not appear in the registered version - http://www.clicktoconvert.com
JNI Code
14
This watermark does not appear in the registered version - http://www.clicktoconvert.com
15
This watermark does not appear in the registered version - http://www.clicktoconvert.com
Code Flow
Application UI Application Code (Java) JNI Code (C/C++)
Callback from
JNI
Function call /
Update UI IPC
Core stack
functionality (C/C++)
16
This watermark does not appear in the registered version - http://www.clicktoconvert.com
18
This watermark does not appear in the registered version - http://www.clicktoconvert.com
java
java aapt MyApp.apk
code data mp3
code
# library calls
19
This watermark does not appear in the registered version - http://www.clicktoconvert.com
Parts of Application
§ Activity
§ View
§ Service
§ Content provider
This watermark does not appear in the registered version - http://www.clicktoconvert.com
Application Components
§Activity
– An activity is needed to create a screen for a user application.
§Intents
– Intents are used to transfer control from one activity to
another.
§ Services
– It doesn't need a user interface. It continues running in the
background with other processes run in the foreground.
§Content Provider
– This component allows the application to share information
with other applications.
21
This watermark does not appear in the registered version - http://www.clicktoconvert.com
22
This watermark does not appear in the registered version - http://www.clicktoconvert.com
Application Components
§ Android applications do not have a single entry point (e.g. no
main() function).
§ They have essential components that the system can
instantiate and run as needed.
§ Four basic components
Components Description
Activity UI component typically corresponding to one screen
Service Background process without UI
Broadcast Receiver Component that responds to broadcast Intents
Content Provider Component that enables applications to share data
23
This watermark does not appear in the registered version - http://www.clicktoconvert.com
Components - Activity
§ An activity is usually a single screen:
– Implemented as a single class extending Activity.
– Displays user interface controls (views).
– Reacts on user input/events.
§ An application typically consists of several screens:
– Each screen is implemented by one activity.
– Moving to the next screen means starting a new activity.
– An activity may return a result to the previous activity.
24
This watermark does not appear in the registered version - http://www.clicktoconvert.com
Examples:
•The “Contacts” application may have an activity that displays a scrolling list
of all contacts listed by last name.
•The “Calculator” app may have an activity that displays a numeric keyboard
and buttons for numeric operations, etc. and awaits inputs from the user.
25
This watermark does not appear in the registered version - http://www.clicktoconvert.com
26
This watermark does not appear in the registered version - http://www.clicktoconvert.com
source: developer.android.com
27
This watermark does not appear in the registered version - http://www.clicktoconvert.com
Components - Service
§ A service does not have a visual user interface, but rather runs
in the background for an indefinite period time.
Example: music player, network download, etc
§ Each service extends the Service base class.
§ It is possible to bind to a running service and start the service
if it's not already running.
§ While connected, it is possible communicate with the service
through an interface defined in an AIDL (Android Interface
Definition Language).
Notification
Communication
Pause/rewind
/stop/restart
28
This watermark does not appear in the registered version - http://www.clicktoconvert.com
Example:
•A common example of a service is an mp3 player that may run in
the background as the user may be involved with some activity of
another app, e.g. web browser.
NOTE:
•Typically, a service may be created, say, by an activity;
Alternatively, a service may be started and running in some other
context, and can announce its interface to other activities –
in this case, the activity may just connect itself to the service, in
Android, this is called “bind”-ing to the service.
29
This watermark does not appear in the registered version - http://www.clicktoconvert.com
30
This watermark does not appear in the registered version - http://www.clicktoconvert.com
§ void onCreate()
§ void onStart(Intent
intent)
§ void onDestroy()
31
31
This watermark does not appear in the registered version - http://www.clicktoconvert.com
SMS
32
This watermark does not appear in the registered version - http://www.clicktoconvert.com
33
This watermark does not appear in the registered version - http://www.clicktoconvert.com
Examples of interrupts:
-Incoming phone call
-Battery is low
34
This watermark does not appear in the registered version - http://www.clicktoconvert.com
Activity
Activity Activity
Activity
Application Application
Content
Content
Activity
Activity Service
Service
Resolver
Resolver
Content
Content Content
Content
Content
Content Provider
Provider
Resolver
Resolver Resolver
Resolver
SQLite Remote
Data
Data XML
XML Store
35
This watermark does not appear in the registered version - http://www.clicktoconvert.com
36
This watermark does not appear in the registered version - http://www.clicktoconvert.com
•Content providers
37
This watermark does not appear in the registered version - http://www.clicktoconvert.com
38
38
This watermark does not appear in the registered version - http://www.clicktoconvert.com
Intent
39
This watermark does not appear in the registered version - http://www.clicktoconvert.com
Intent
40
This watermark does not appear in the registered version - http://www.clicktoconvert.com
Intent filter
action
category
data
41
This watermark does not appear in the registered version - http://www.clicktoconvert.com
Intents
startActivity(new Intent(Intent.VIEW_ACTION,
Uri.parse("http://www.fhnw.ch"));
startActivity(new Intent(Intent.VIEW_ACTION,
Uri.parse("geo:47.480843,8.211293"));
startActivity(new
Intent(Intent.EDIT_ACTION,Uri.parse("content://contacts/people/1"));
42
This watermark does not appear in the registered version - http://www.clicktoconvert.com
Intents (Cont)
§ Intent Filters
ü A component's intent filters in the manifest file inform
Android of the kinds of intents the component is able to
handle.
ü An example
43
This watermark does not appear in the registered version - http://www.clicktoconvert.com
Intents (Cont)
44
This watermark does not appear in the registered version - http://www.clicktoconvert.com
Android Team
CEMT Products Group
BGH_Team_Android@aricent.com
45