Activity - Homepages | The University of Aberdeen

Download Report

Transcript Activity - Homepages | The University of Aberdeen

Mobile app workflow
(Java ME & Android Clients)
Mobile Computing
Bruce Scharlau, University of Aberdeen, 2012
Some materials from MobEdu.net
What process would you use for
a mobile app?
Bruce Scharlau, University of Aberdeen, 2012
Constantly changing market means
focus on learning basics
PDAs are gone and mobiles change
Bruce Scharlau, University of Aberdeen, 2012
http://www.sheldoncomics.com/archive/050222.html
Mobile computing offers a new
novel dimension
This is still a new programming dimension
compared to desktop and conventional
distributed computing.
Bruce Scharlau, University of Aberdeen, 2012
Understand the process
http://www.abdn.ac.uk/%7Ecsc228/teaching/CS5942/information/the_process_handout.pdf
Bruce Scharlau, University of Aberdeen, 2012
Use tools, or not, as needed
Paper and pens work great to validate
concept ideas, then progress to wireframe
http://speckyboy.com/2012/02/22/tips-forwireframing-a-usable-mobile-app-interface/
Bruce Scharlau, University of Aberdeen, 2012
Always be validating ideas
Build
Learn
Measure
http://theleanstartup.com/principles
Bruce Scharlau, University of Aberdeen, 2012
Variety of cross-platform tools
Consider options of platforms and route to
market
http://en.wikipedia.org/wiki/Mobile_applicatio
n_development
Bruce Scharlau, University of Aberdeen, 2012
Speed up testing process
Use tools to automate tests and other
repetitive tasks
http://www.gorillalogic.com/testingtools/monkeytalk
http://www.soasta.com/products/cloudtestlite/
Bruce Scharlau, University of Aberdeen, 2012
Why might you not want to hit
all platforms at once?
Bruce Scharlau, University of Aberdeen, 2012
Understand the process
http://www.abdn.ac.uk/%7Ecsc228/teaching/CS5942/information/the_process_handout.pdf
Bruce Scharlau, University of Aberdeen, 2012
The rest covers basics of
Java mobile and Android clients
Bruce Scharlau, University of Aberdeen, 2012
Java Family
Source: http://java.sun.com/developer/onlineTraining/webcasts/pdf/toronto/bday.pdf
Bruce Scharlau, University of Aberdeen, 2012
J2ME and J2EE connect easily
Source: http://java.sun.com/blueprints/earlyaccess/wireless/designing/designing.pdf
Bruce Scharlau, University of Aberdeen, 2012
Java ME Components
PDA
Phone
MIPD
Profile
CLDC
Configuration
KVM
• Hosting OS
• KVM – execution
engine with
simplified JVM
• CLDC – base
library
• MIDP – additional
libraries
Bruce Scharlau, University of Aberdeen, 2012
Configurations
• CLDC – Connected,
limited device
configuration – assume
disconnection
• CDC = Connected
device configuration –
assume always
connected
Bruce Scharlau, University of Aberdeen, 2012
Example Java ME Stack
Source:
http://java.sun.com/developer/onlineTraining/webcasts/pdf/toronto/bday.pdf
Bruce Scharlau, University of Aberdeen, 2012
•
CLDC Scope differs from core
Java
Main differences:
•
•
•
•
•
•
•
•
No floating point support required
No finalisation of object instances
Limited error handling
No thread groups, reflection, JNI
Core java.* libraries
I/O and networking
Security and Internationalisation
New classes, javax.microedition.*
Bruce Scharlau, University of Aberdeen, 2012
‘extra’ APIs can enhance applications
Just remember that they are ‘optional’, so may not be available
Bruce Scharlau, University of Aberdeen, 2012
http://java.sun.com/javame/overview/products.jsp
CLDC Classes need pre-verification
Source:
http://java.sun.com/developer/onlineTraining/webcasts/pdf/toronto/bday.pdf
Bruce Scharlau, University of Aberdeen, 2012
Mobile Information Device Profile (MIDP)
• Targets two-way devices implementing CLDC
• Provides
–
–
–
–
–
–
–
–
Application model, ie lifecycle and packaging
Display toolkit, UI methods
Persistent data storage
HTTP 1.1 networking using CLDC GCF
MIDP 1.0 widely available
MIDP 2.0 released Nov. 2002
MIDP 2.1 released summer 2006
MIDP 3 out in beta spring 2009
Bruce Scharlau, University of Aberdeen, 2012
Midlets are packaged in jars with
required resources
MyApp.jar
Com/package/classes
META-INF/MANIFEST.MF
Mylogo.png
MyApp.jad
Bruce Scharlau, University of Aberdeen, 2012
Jad and Manifest are similar
required files for Java ME apps
AuctionMidlet.jad
MIDlet-1: AuctionMIDlet,,com.auction.j2me.AuctionMIDlet
MIDlet-Jar-URL: AuctionMidlet.jar
MIDlet-Name: AuctionMidlet Midlet Suite
MIDlet-Vendor: Midlet Suite Vendor
MIDlet-Version: 1.0.0
MicroEdition-Configuration: CLDC-1.1
MicroEdition-Profile: MIDP-2.1
MIDlet-Jar-Size: 4396
Bruce Scharlau, University of Aberdeen, 2012
Manifest goes in the jar file
MANIFEST.MF
Manifest-Version: 1.0
MicroEdition-Configuration: CLDC-1.1
MIDlet-Name: AuctionMidlet Midlet Suite
Ant-Version: Apache Ant 1.6.3
Created-By: 1.5.0_14-b03 (Sun Microsystems Inc.)
MIDlet-Vendor: Midlet Suite Vendor
MIDlet-1: AuctionMIDlet,,com.auction.j2me.AuctionMIDlet
MIDlet-Version: 1.0.0
MicroEdition-Profile: MIDP-2.1
Bruce Scharlau, University of Aberdeen, 2012
The JAD references the JAR
Download of JAD for Over The Air (OTA)
provisioning means opening:
– The AMS downloads the JAR by the
information in the JAD
– Mostly the JAR and the JAD are in similar
folder
AMS =Application Management System
Bruce Scharlau, University of Aberdeen, 2012
The JAD is validated by the AMS
(Application Management System)
• Is the CLDC version correct?
• Is the MIDP version correct?
• Is there enough memory to download the
MIDlet?
• Where is the JAR file?
• Where is the execution unit inside the
JAR?
Bruce Scharlau, University of Aberdeen, 2012
MIDlet Development
1.
2.
3.
4.
5.
6.
Write Java application
Compile
Preverify (and obfuscate)
Package into Jar file
Create deployment descriptor (jad)
Deploy and run in toolkit or other device
Bruce Scharlau, University of Aberdeen, 2012
Preverify to check that classes are
correct
• All classes automatically preverified after
code is compiled
• If it fails, then error message is passed
back to the console
• Automatically packages app using name
of application directory
Bruce Scharlau, University of Aberdeen, 2012
MIDP applications (MIDlets) move
from state to state implementing
three methods
Bruce Scharlau, University of Aberdeen, 2012
MIDlet must implement three
methods:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class HelloMidlet extends MIDlet {
public void startApp() {
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
Bruce Scharlau, University of Aberdeen, 2012
MIDlet needs other key parts
• Import the packages
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
• All MIDlet extends from the MIDlet class
public class HelloMidlet extends MIDlet implements
CommandListener {
• Furthermore it implements the
CommandListener class
Bruce Scharlau, University of Aberdeen, 2012
MIDlet needs to initialise and
create variables
// Initialize the variables
private Form form;
private Display display;
private Command exitCommand;
Bruce Scharlau, University of Aberdeen, 2012
MIDlet use startApp() to move to
active state
• The MIDlet starts at the call of the startApp()
public void startApp() {
form = new Form("Hello");
display = Display.getDisplay(this);
exitCommand = new Command("Exit", Command.SCREEN, 1);
form.addCommand(exitCommand);
form.setCommandListener((CommandListener)this);
form.append(new StringItem("Hello", "Hello World!"));
display.setCurrent(form);
}
• Commands and the StringItem is added to the Form
• Show the Form on the display
Bruce Scharlau, University of Aberdeen, 2012
The commandAction() method
handles the incoming commands
public void commandAction(Command command, Displayable
screen) {
if ( command == exitCommand ) {
destroyApp(true);
notifyDestroyed();
}
}
Bruce Scharlau, University of Aberdeen, 2012
If it’s not used leave it empty
The following methods are unused, so we
leave them empty
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
Bruce Scharlau, University of Aberdeen, 2012
Before and after start
Bruce Scharlau, University of Aberdeen, 2012
Android is part of the ‘build a
better phone’ process
Open Handset Alliance produces
Android
Comprises handset manufacturers,
software firms, mobile operators, and
other manufactures and funding
companies
http://www.openhandsetalliance.com/
Bruce Scharlau, University of Aberdeen, 2012
Android makes mobile Java easier
Well, sort of…
Bruce Scharlau, University of Aberdeen, 2012
http://code.google.com/android/goodies/index.html
Android applications are written
in Java
package com.google.android.helloactivity;
import android.app.Activity;
import android.os.Bundle;
public class HelloActivity extends Activity {
public HelloActivity() {
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.hello_activity);
}
Bruce Scharlau, University of Aberdeen, 2012
}
Android applications are
compiled to Dalvik bytecode
Write app in Java
Compiled in Java
Transformed to Dalvik bytecode
Loaded into Dalvik VM
Linux OS
Bruce Scharlau, University of Aberdeen, 2012
The Dalvik runtime is optimised
for mobile applications
Run multiple VMs efficiently
Each app has its own VM
Minimal memory footprint
Bruce Scharlau, University of Aberdeen, 2012
Android has many components
Bruce Scharlau, University of Aberdeen, 2012
Can assume that most have
android 2.1, 2.2 or newer
Bruce Scharlau, University of Aberdeen, 2012
http://developer.android.com/resources/dashboard/platform-versions.html
Android has a working emulator
Bruce Scharlau, University of Aberdeen, 2012
All applications are written in
Java and available to each other
Android designed to enable reuse of
components in other applications
Each application can publish its
capabilities which other apps can use
Bruce Scharlau, University of Aberdeen, 2012
Android applications have
common structure
Views such as
lists, grids, text
boxes, buttons,
and even an
embeddable web
browser
An Activity Manager that
manages the life cycle of
applications and provides
a common navigation
backstack
Content
Providers that
enable
applications to
access data from
other applications
(such as
Contacts), or to
share their own
data
A Notification Manager
that enables all apps to
display custom alerts in the
status bar
A Resource Manager,
providing access to noncode resources such as
localized strings,
graphics, and layout files
Bruce Scharlau, University of Aberdeen, 2012
Android applications have
common structure
Broadcast
receivers can
trigger intents that
start an application
Data storage
provide data for
your apps, and
can be shared
between apps –
database, file,
and shared
preferences
(hash map) used
by group of
applications
Activity is the presentation
layer of your app: there will
be one per screen, and the
Views provide the UI to the
activity
Intents specify what
specific action should be
performed
Services run in the
background and have
no UI for the user –
they will update data,
and trigger events
Bruce Scharlau, University of Aberdeen, 2012
There is a common file structure
for applications
code
Autogenerated
resource list
files
images
UI layouts
constants
Bruce Scharlau, University of Aberdeen, 2012
Standard components form
building blocks for Android apps
Notifications
Has life-cycle
Activity
screen
Views
Intents
App to handle content
Service
Background app
Like music player
manifest
ContentProviders
Bruce Scharlau, University of Aberdeen, 2012
Other applications
The AndroidManifest lists
application details
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.my_domain.app.helloactivity">
<application android:label="@string/app_name">
<activity android:name=".HelloActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category
android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
Bruce Scharlau, University of Aberdeen, 2012
Activity is one thing you can do
Bruce Scharlau, University of Aberdeen, 2012
From fundamentals page in sdk
Intent provides late running
binding to other apps
It can be thought of as the glue between
activities. It is basically a passive data
structure holding an abstract description of
an action to be performed.
Written as action/data pairs such as:
VIEW_ACTION/ACTION content://contacts/1
Bruce Scharlau, University of Aberdeen, 2012
Services declared in the manifest
and provide support
Services run in the background:
Music player providing the music playing in
an audio application
Intensive background apps, might need to
spawn their own thread so as to not block
the application
Bruce Scharlau, University of Aberdeen, 2012
Notifications let you know of
background events
This way you know that an SMS arrived,
or that your phone is ringing, and the
MP3 player should pause
Bruce Scharlau, University of Aberdeen, 2012
ContentProviders share data
You need one if your application shares data
with other applications
This way you can share the contact list with the
IM application
If you don’t need to share data, then you can
use SQLlite database
Bruce Scharlau, University of Aberdeen, 2012
UI layouts are in Java and XML
setContentView(R.layout.hello_activity);
//will load the XML UI file
Bruce Scharlau, University of Aberdeen, 2012
Security in Android follows
standard Linux guidelines
Each application runs in its own process
Process permissions are enforced at user
and group IDs assigned to processes
Finer grained permissions are then
granted (revoked) per operations
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.app.myapp" >
<uses-permission id="android.permission.RECEIVE_SMS" />
</manifest>
Bruce Scharlau, University of Aberdeen, 2012
There are lots of sources of
information
• The sdk comes with the API references,
sample applications and lots of docs
• Blog http://android-developers.blogspot.com/
which has lots of useful examples, details
• There is http://www.anddev.org
Bruce Scharlau, University of Aberdeen, 2012
Summary
Use memory responsibly for best performance
Create clients using appropriate CLDC and
MIDP libraries
Bruce Scharlau, University of Aberdeen, 2012