610 likes | 790 Vues
Mobile app workflow (Java ME & Android Clients). Mobile Computing. Some materials from MobEdu.net. What process would you use for a mobile app?. Constantly changing market means focus on learning basics. PDAs are gone and mobiles change. http://www.sheldoncomics.com/archive/050222.html.
E N D
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-for-wireframing-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_application_development Bruce Scharlau, University of Aberdeen, 2012
Speed up testing process Use tools to automate tests and other repetitive tasks http://www.gorillalogic.com/testing-tools/monkeytalk http://www.soasta.com/products/cloudtest-lite/ 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 • Hosting OS • KVM – execution engine with simplified JVM • CLDC – base library • MIDP – additional libraries Phone PDA MIPD Profile CLDC Configuration KVM 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 • 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 // Initializethe 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
Linux OS Loaded into Dalvik VM Android applications are compiled to Dalvik bytecode Write app in Java Compiled in Java Transformed to Dalvik bytecode 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 non-code 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 Activity is the presentation layer of your app: there will be one per screen, and the Views provide the UI to the activity 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 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 App to handle content Intents Background app Like music player Service manifest ContentProviders Other applications Bruce Scharlau, University of Aberdeen, 2012
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