28
Non-Native Android Development Stacy Devino Stephen Wylie 8/9/2012 (C) 2012 Stephen Wylie & Stacy Devino

Non-Native Android Development

  • Upload
    asher

  • View
    22

  • Download
    0

Embed Size (px)

DESCRIPTION

Non-Native Android Development. Stacy Devino Stephen Wylie 8/9/2012. Comparison of several non-native platforms. jQuery Mobile - Pros. S upports JSON E asy API integration Uses a Web View front end Prebuilt packages, theming easily drive professional results - PowerPoint PPT Presentation

Citation preview

Page 1: Non-Native Android Development

(C) 2012 Stephen Wylie & Stacy Devino

Non-Native Android DevelopmentStacy DevinoStephen Wylie8/9/2012

Page 2: Non-Native Android Development

(C) 2012 Stephen Wylie & Stacy Devino

Comparison of severalnon-native platforms

Page 3: Non-Native Android Development

(C) 2012 Stephen Wylie & Stacy Devino

jQuery Mobile - Pros Supports JSON Easy API integration Uses a Web View front end Prebuilt packages, theming easily drive

professional results Build mobile app & mobile site with same

code Supported on every smartphone platform Quick prototyping and easy to "theme"

using CSS (proto app in less than a day)

Page 4: Non-Native Android Development

(C) 2012 Stephen Wylie & Stacy Devino

jQuery Mobile - Cons Slow if large Never as quick as native Best for simple or web interactive

applications

Page 5: Non-Native Android Development

(C) 2012 Stephen Wylie & Stacy Devino

Phonegap - Pros Full HTML5 viewer Build & develop using familiar Web tools Fast development with full cross

compatibility Easy to build with little native code Plugins:

Many provided for interacting with hardware

Easy to roll your own for other features (NFC, BT, Native Android)

Page 6: Non-Native Android Development

(C) 2012 Stephen Wylie & Stacy Devino

Phonegap No limits to what you can add Add all the packages for theming that you want Use any IDE you want, compiling and

upgrading is very easy

Cons: Slower than full native code Requires you to do cross code hoping for

something complicated You have to be pretty smart to do add-ons that

work well

Page 7: Non-Native Android Development

(C) 2012 Stephen Wylie & Stacy Devino

Titanium - Pros Generates full native code Prebuilt packages  Cross-platform for Android, iOS Full IDE with many debugging features Things work as expected

Page 8: Non-Native Android Development

(C) 2012 Stephen Wylie & Stacy Devino

Titanium - Cons IDE support from dev team is limited Additional features not present Creating new features nearly impossible Only builds for iOS and Android Hard to root-cause memory leak issues

(problems from the IDE/package)

Page 9: Non-Native Android Development

(C) 2012 Stephen Wylie & Stacy Devino

Sencha - Pros Very fast for non native Quick to learn and use for Web devs  Cross platform for iOS and Android Can prototype on a web view Very good HTML5 support Built for web interactive, custom view

content

Best for simple custom apps with a static feature set that won’t expand after release

Page 10: Non-Native Android Development

(C) 2012 Stephen Wylie & Stacy Devino

Sencha - Cons Can take a while to build something

novel Libraries are not huge Building new features can be a pain

Page 11: Non-Native Android Development

(C) 2012 Stephen Wylie & Stacy Devino

Stackmob - Pros Huge API, IDE support Can service other apps  Built for Java,

JavaScript, and HTML5 Build your own API's

and combos Oauth, advanced

analytics support included

Can do advanced logic

-- twitter, facebook, etc.

-- quick learning curve for Android devs-- great for if looking to do a mash-up app-- HUGE if you have ever dealt with Oauth

Page 12: Non-Native Android Development

(C) 2012 Stephen Wylie & Stacy Devino

Stackmob - Cons Some features poorly supported across devices Non-native code  Must build in a native language (Java) Documentation is not great  Requires web connection to do anything useful

Page 13: Non-Native Android Development

Development Time ComparisonjQuery Mobile Fastest

Phonegap

Sencha

Titanium / Stackmob (tie)

Native Android Slowest

(C) 2012 Stephen Wylie & Stacy Devino

Page 14: Non-Native Android Development

(C) 2012 Stephen Wylie & Stacy Devino

A closer look at PhoneGap/Cordova

Page 15: Non-Native Android Development

(C) 2012 Stephen Wylie & Stacy Devino

PhoneGap (Cordova) + jQuery Mobile jQuery: Robust JavaScript API for

Manipulating HTML DOM Processing HTTP requests with AJAX

jQuery-UI: Slick-looking user interface elements Too slow for mobile use

jQuery Mobile: Best of both worlds Plenty of examples online

Page 16: Non-Native Android Development

(C) 2012 Stephen Wylie & Stacy Devino

Cordova + jQM QM provides mobile-inspired event

listeners Performance can be slow Caused by 300ms delay waiting for

additional touches Work around with fastclick.js -

https://github.com/dave1010/jquery-fast-click/

Page 17: Non-Native Android Development

(C) 2012 Stephen Wylie & Stacy Devino

Remember SliderSwitch?

Here’s how to do it in JS & jQuery…

Page 18: Non-Native Android Development

(C) 2012 Stephen Wylie & Stacy Devino

Plugins Many default PhoneGap plugins provide

access to extended device features Accelerometer Camera Contacts DB…

Sometimes you need to roll your own Extra sensor, memory-intensive view, etc. Need a JavaScript portion & an Android

intent

Page 19: Non-Native Android Development

Plugins - JavaScript Cordova.exec() invokes native code Requires five arguments

Success callback (JS function) Failure callback (JS function) String reference to native code class String reference to an action Array of parameters

(C) 2012 Stephen Wylie & Stacy Devino

Page 20: Non-Native Android Development

(C) 2012 Stephen Wylie & Stacy Devino

Plugins - JavaScriptvar MenuIntent = function() { };MenuIntent.prototype.startActivity = function(city) {return PhoneGap.exec(function(args) { menuSuccess(args); }, function(args) { menuFail(args); }, 'MenuPlugin', 'startActivity', [city, selectedCheckArr, specials]);};

// Called by:window.plugins.menuIntent.startActivity(city);

Page 21: Non-Native Android Development

(C) 2012 Stephen Wylie & Stacy Devino

Plugins – Native Java Override the Plugin class Implement the execute function:public PluginResult execute(String action, JSONArray args, String callbackId)

Implement means to return resultsPluginResult result = new PluginResult(PluginResult.Status.[OK|ERROR], data);result.setKeepCallback(false);this.[success|error](result, this.callback);this.callback = "";

Page 22: Non-Native Android Development

(C) 2012 Stephen Wylie & Stacy Devino

Plugins – Native Java Could write the whole plugin in

execute() Need further modification to await

asynchronous results User input, file download, etc.

execute() Provide temporary callback result

Call doActivity(

)

doActivity() Launch an asynchronous activity, such as an Intent

onActivityResult()

Analyze results from returned activity

Return success or

failure

Page 23: Non-Native Android Development

(C) 2012 Stephen Wylie & Stacy Devino

Example menuplugin.js MenuPlugin.java

Page 24: Non-Native Android Development

(C) 2012 Stephen Wylie & Stacy Devino

SQL DB SubstitutesBuild your backend with APIs & the cloud. Extremely NoSQL approach Data stored as “array of arrays” Write your own API to access dataTwo popular choices: Proxomo APIgee

Page 25: Non-Native Android Development

(C) 2012 Stephen Wylie & Stacy Devino

SQL DB Substitutes

MobileApp

• In JavaScript• Provides user interaction within your app• Calls AJAX routine in JavaScript when desired

YourServer

• In PHP, ASP.NET, or your favorite server-side language

• Makes request to the Proxomo/Apigee API• Prints result as the HTTP response

Callback

• In JavaScript, asynchronous• Takes response and updates UI

Page 26: Non-Native Android Development

(C) 2012 Stephen Wylie & Stacy Devino

SQL DB Substitutes “NoSQL” means NO SQL.

No Joins! Not constrained to a schema

How do you join? Denormalize your tables keep them in

sync Implement join logic in application layer

Data validation is up to you Think of last time with Linden Darling

Page 27: Non-Native Android Development

(C) 2012 Stephen Wylie & Stacy Devino

SQL DB Substitutes Setting up the API can be painful

So many queries & data interactions Lots of repetitive code

Take security into consideration HTTP GET is totally plaintext

validateUser.php?user=stevo&pass=stockmktking

Use HTTPS wherever possible

Page 28: Non-Native Android Development

(C) 2012 Stephen Wylie & Stacy Devino

Example qw_ajax.php