Simple Offline Data Synchronization for Mobile Web and PhoneGap Applications

Being able to work offline is an expected feature of mobile applications. For data-driven applications, it means that you — the developer — will have to store (a subset of) your application data locally, and implement a data synchronization mechanism that keeps your local and server data in sync.

In this article, I describe a simple data synchronization strategy that uses the device’s (or browser’s) SQLite database. The implementation currently leverages the Web SQL API (even though the W3C is no longer actively maintaining the spec) because both iOS and Android support it, but they don’t support IndexedDB, the official alternative. However, the API described below — getLastSync(), getChanges(), applyChanges() — defines a generic synchronization contract, and the solution can be expanded and made “pluggable”: You could create different synchronization objects, each providing a different implementation of these methods. You could then choose which object to plug in based on the context and the platform your application is running on.

Try it in the Playground


[Read more...]

Sample Mobile App with Backbone.js, PhoneGap, and a Local Database

In my previous post, I shared a simple Wine Cellar application built with Backbone.js and packaged as a mobile app with PhoneGap. That version of the application gets its data from a set of RESTful services, which means that you can only use it while online.

In this post, we explore an offline version of the same application: this new version gets its data from your device’s local database using the PhoneGap SQL database API.

By default, Backbone.js Models access their data using RESTful services defined by the Models “url” and “urlRoot” attributes. But Backbone.js also makes it easy and elegant to change your Models data access mechanism: All you have to do is override the Backbone.sync method. From the Backbone.js documentation:

Backbone.sync is the function that Backbone calls every time it attempts to read or save a model to the server. By default, it uses (jQuery/Zepto).ajax to make a RESTful JSON request. You can override it in order to use a different persistence strategy, such as WebSockets, XML transport, or Local Storage.

The documentation includes a useful example that shows how to replace the default Backbone.sync implementation with localStorage-based persistence where models are saved into JSON objects.

In our application, we will replace the default Backbone.sync implementation with SQL-based persistence using the device’s local database.
[Read more...]

Sample Mobile App with Backbone.js and PhoneGap

I recently blogged a tutorial (part 1, part 2, part 3, and postface) that takes you through the process of building a CRUD application using HTML and the Backbone.js framework. The application used in this tutorial is a Wine Cellar management app, and I thought it would be fun to create a Mobile version using PhoneGap.

PhoneGap — if you are not familiar with it — is an open source platform that allows you develop cross-platform Mobile applications using HTML and JavaScript. Specifically, it allows you to:

  1. Package an HTML application as a native app on all the key mobile platforms (iOS, Android, BlackBerry, Windows Phone, WebOS, Symbian, Bada).
  2. Access your device capabilities (Camera, GPS, database, accelerometer, etc) using a cross-platform JavaScript API.

Backbone.js is a great framework to give structure to your web application regardless of where it is running: in a traditional Web Browser, or as an app packaged with PhoneGap.

So, here is the app…
[Read more...]

jQuery Mobile "Getting Started" Application

A couple of weeks ago, I shared an Employee Directory sample application built with jQuery Mobile and PhoneGap. That application was implemented “Ajax-style”, keeping the UI and the data access code cleanly separated. In other words: no server code intermingled in the HTML markup.

A number of people have asked for a similar example using a “classic” (non-Ajax) implementation where pages (markup + data) are entirely built at the server-side before being delivered to the client.

So, here is simpler version of the same application built “sans Ajax”. I used PHP in this version, but you can of course use your favorite server-side technology (Java, .NET, CF, RoR, etc).

[Read more...]

Flex / Spring Mobile Test Drive: Learn the Best Way to Build Java-Backed iOS, Android and PlayBook Apps

Flex is a powerful application framework for building first-class mobile applications for iOS, Android, and the BlackBerry PlayBook using a single programming model, a single tool, and a single code base.

If you are a Java developer, the Flex programming model is also easy to master because it is syntactically very close to Java. The Flex IDE (Flash Builder) is a plugin on top of Eclipse, which means that you can write, debug, and profile your client and server code in the same development environment.

You can also easily integrate Flex applications with a Java back end using the Remoting and Messaging services provided by BlazeDS (open source) or LCDS (commercial license). For Spring developers, the integration is even easier and more powerful using the Spring/BlazeDS integration project, which makes the Flex and Spring combination the best way to build cross-platform iOS, Android, and PlayBook applications with a Java back end.
[Read more...]

MobileTrader for iOS, Android, and PlayBook: Source code now available on GitHub

I made some changes to the MobileTrader application and took the opportunity to push the source code to GitHub. You can get it here: https://github.com/ccoenraets/MobileTrader

This version was built with the shipping version of Flex and Flash Builder 4.5.1 which has built-in support for iOS, Android and the BlackBerry PlayBook.

The most notable change in this version is that I enabled the real time collaboration feature (with your financial advisor). This includes video conference, user interface synchronization, etc. You will need a LiveCycle Collaboration Service room URL to enable this feature. You can sign up for a developer version here: https://afcs.acrobat.com. You can still use the application without enabling the real time collaboration feature.

Usual disclaimer about the source code: This is a sample application, I intentionally cut some corners, etc.

[Read more...]

Three Platforms, One application: MobileTrader for iOS, Android, and PlayBook Source Code Available

My recent video, Flex on the iPad, has generated a lot of interest. The same application runs on iOS, Android, and the BlackBerry PlayBook. A number of you have asked me for the source code. Now that Flex 4.5 has been released, I’m able to share it: you can download the project file here.

NOTE: The shipping version of Flash Builder 4.5 provides full support for Flex projects on Android. Support for Flex projects on iOS and the PlayBook will be available in a June update. More information here.

Usual disclaimer about the source code: This is a sample application, I intentionally cut some corners, etc.

[Read more...]

Flex Charts on the iPad

I continue to see a lot of interest for dashboards applications on mobile devices (particularly on tablets), and I think that interactive data visualization applications are really a sweet spot for Flex. As an example, I built a simple dashboard aggregator using the out-of-the box charting components available in Flex. The same application can run on iOS (iPhone/iPad/iPod Touch), Android devices, and on the BlackBerry PlayBook. If you are an existing Flex developer, this will look very familiar: these are the same charts you also run in the browser or on the desktop on traditional computers. Check out the video:

For more data-visualization applications built with Flex, check out the Mobile Trader and the Sales Pipeline applications.

Usual disclaimer: I’m not a designer, so this is mostly developer artwork. You can of course polish, customize and style the out-of-the-box-experience.

Flex-Powered Multi-Touch Data Visualization on the iPad, Android, and the BlackBerry PlayBook

Over the past couple of weeks, I’ve visited many enterprise customers to spread the exciting news and discuss their mobile strategy. I found it interesting that most of them were focusing primarily on tablets (instead of phones), and that the application they were focusing on was almost always a dashboard or at least involved a lot of charting components. It is true that tablets such as the iPad, the Xoom, and the BlackBerry PlayBook are amazing devices for data visualization.

[Read more...]

New Mobile Trader Desktop Demo App for Android

I built a new “Mobile Trader Desktop” application that I published on the Android Market. This is a demo application (with simulated data) built with Flex “Hero” and running on AIR for Android.

To install the application, just search for “Mobile Trader” on the Android Market, or access the following URL from your device’s browser: market://search?q=pname:air.MobileTrader.

You can download the source code (project file) here. You need Flash Builder Burrito (available here) to open this project.

Quick Application Walkthrough

The “Assets” tab shows a summary of your investment portfolio’s progress. You can use swipe and zoom gestures on the chart at the bottom of the screen to navigate through historical data. Notice that if you rotate your device (in landscape), the layout changes to display a full screen view of the chart. The charts in this application are built using simple FXG paths (not mx charts).


[Read more...]