280 likes | 384 Vues
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
E N D
Non-Native Android Development Stacy Devino Stephen Wylie 8/9/2012 (C) 2012 Stephen Wylie & Stacy Devino
Comparison of severalnon-native platforms (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) (C) 2012 Stephen Wylie & Stacy Devino
jQuery Mobile - Cons • Slow if large • Never as quick as native • Best for simple or web interactive applications (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) (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 (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 (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) (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 (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 (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 (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 (C) 2012 Stephen Wylie & Stacy Devino
Development Time Comparison (C) 2012 Stephen Wylie & Stacy Devino
Acloser look at PhoneGap/Cordova (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 (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/ (C) 2012 Stephen Wylie & Stacy Devino
Remember SliderSwitch? Here’s how to do it in JS & jQuery… (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 (C) 2012 Stephen Wylie & Stacy Devino
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
Plugins - JavaScript varMenuIntent = 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); (C) 2012 Stephen Wylie & Stacy Devino
Plugins – Native Java • Override the Plugin class • Implement the execute function:public PluginResult execute(String action, JSONArrayargs, 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= ""; (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. (C) 2012 Stephen Wylie & Stacy Devino
Example • menuplugin.js • MenuPlugin.java (C) 2012 Stephen Wylie & Stacy Devino
SQL DB Substitutes Build your backend with APIs & the cloud. • Extremely NoSQL approach • Data stored as “array of arrays” • Write your own API to access data Two popular choices: • Proxomo • APIgee (C) 2012 Stephen Wylie & Stacy Devino
SQL DB Substitutes (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 (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 plaintextvalidateUser.php?user=stevo&pass=stockmktking • Use HTTPS wherever possible (C) 2012 Stephen Wylie & Stacy Devino
Example • qw_ajax.php (C) 2012 Stephen Wylie & Stacy Devino