Tuesday, January 17, 2012

Android: Native or HTML 5 Applications


The biggest mistake made by companies in today's mobile environment is writing native applications when using HTML 5 would be more appropriate.

What is HTML 5? Broadly speaking, it includes the technologies for: HTML mark-up, Javascript and Cascading Style Sheets. It includes support for amongst other technologies: geo-location, audio & video, web storage, multi-touch, device orientation, speech recognition,  and the Javascript equivalent of threads: web workers. As you can see, HTML 5 goes well beyond the capabilities of earlier web technologies.

Using HTML 5 reduces the cost of development and expands the reach of the application. By doing an Android application in HTML 5, it only requires minor tweaks to bring it to iPhone, WinPhone and other platforms.

What is the case for doing native applications? Given that we can reach many more devices by using HTML 5, we should consider the justifications:
  • Broader access to the underlying hardware and sensors
    • Camera
    • Barometer
  • Tighter integration with system features: 
    • Notifications
    • Home Screen Widgets
  • Ability to integrate with other applications 
    • Launch the native Facebook application
    • Use the Android software bus (Intents) to pass it data
  • Faster, smoother and can be more attractive
  • More explicit management of resources
    • Battery
    • Memory
  • First access to new features not yet accessible through HTML 5
  • Achieving a native look and feel
  • Access to advanced UI components
    • Renderscript: 3D views utilizing hardware acceleration
      • The You Tube application's wall of videos
      • The playlist carousel used in the standard Honeycomb media player
    • Other views that have no HTML 5 equivalent: StackView for example 
An attractive alternative is to create a hybrid application. This is accomplished by embedding a web view inside a native application. Android provides excellent facilities for passing data between the native and HTML 5 portions of the application. For example, you can use WebView.loadUrl from the SDK to evaluate Javascript within a web page and return the results for parsing and further processing. In the opposite direction, Javascript can talk to native components using the WebView's  Javascript interface. For example:
WebView.addJavaScriptInterface(new BarometerReader(), "barometer");
Hybrid applications are more discoverable than pure web applications. Web applications can made available through the Chrome Web Store which is analogous to the Android Store. See the following screenshot of a Chrome browser with Angry Birds installed from the Chrome Web Store:


While this is great, it suffers from several issues:
  • Chrome has not yet been ported to Android
  • There is no section in the Android Market for web applications -> No equivalent of the Chrome Application Store
  • Creating a pure web application does not allow for a home screen launch icon on your mobile device
I imagine the Chrome Web Store will eventually be integrated into the Android Market in such a way that the user will not need to initially know if an application is native or pure HTML 5. But at the moment, it makes sense to create hybrid applications if for no other reason than they are more discoverable. By hybrid, we mean at a minimum embedding a web view inside of a native Dalvik application.

In conclusion, companies should be looking at writing Hybrid applications using HTML 5 to broaden their reach and to utilize the existing skills that exist within their organisations. This is especially true if the application in question is primarily a content application such as a newspaper or magazine. HTML 5 is the future and will increasing replace native applications written for specific platforms.

Glen Cook
Consultant at eWhizMobile


Sources:
Android: Native vs. HTML 5 Applications
Introduction to HTML 5
SDK Documentation: WebView

No comments:

Post a Comment