How we do cross platform mobile app development at Nintex

Maintaining your business presence or mobile apps on different platforms is challenging. A lot of companies hire platform specific developers, form one team for each platform which work in their own silos, each responsible to maintain their respective platform, having different implementation, different code paths and different kind of design. Each team may or may not have face similar functional/UI issues.

At Nintex, we build and ship native mobile apps across iOS, Android and Windows platforms to support access to workflows and forms securely from wherever you are on your mobile devices. Here we have followed a slightly different approach where we design and implement any feature once and then we port the implementation to other platforms. Therefore we have feature based mobile developers which design and implement each feature across Android, iOS and Windows platform.

This has work really good for us, breaking the silos and help us achieve design and code path consistency across multiple platforms.

This often lead us concluding that if we have functional bug in one platform, chances are we have that bug in other platforms as well.

The crux of the idea is that we follow Model-View-ViewModel (MVVM) pattern across all platforms. So we have similar classes for model, view and view-model, contracts, repositories, helpers etc. across Windows, iOS and Android. By similar classes I mean, similar name, code path and structure yet they are written in their own platform specific languages. So if we have a view model with a method on one platform, we will have it across all.

MVVM
MVVM

As an example, consider following sample snippet of a view model from Android and iOS and you will see the point here.

ViewModel in Android (Java)
ViewModel in Android
ViewModel in iOS (Obj-C)

However view, which comprises of UI and code, can be platform specific. e.g.
In Android, View = XML Layout + Activity
In iOS, View = Storyboard + ViewController
In Windows, View = XAML + Code behind

Each view has reference to its view model (initialized through IoC or passed by its parent) where all user interactions are done through events or binding or listeners etc. depending on platform. For instance, in iOS we leverage KVO to observe value change in ViewModel to reflect update to View/UI and stuff like button click is simply routed back to ViewModel method either via simple method call or some mechanism. So our views are just there to render UI widgets/components/layout.

The advantage of this approach is, first, it gives us shared design and code consistency, second, it gives opportunity to open a cross platform conversation and knowledge across team, third, it improve code testability by decoupling UI logic from View (ViewControllers/Activity/CodeBehind) to ViewModel, fourth, it makes relatively easy for us to follow SOLID principles.

However, we have came across challenges with platform specific components like showing alerts/notification, http clients, retrieving geolocation etc. The way we handle it is by injecting contract (interface/protocol) to ViewModel class which has platform specific implementation however code structure remains same in ViewModel across all platforms.

If you are interested to see some sample yet naive MVVM implementation:
MVVM implementation in Android
MVVM implementation in Windows Store and Windows Phone

How do you develop cross platform native apps? It would be interesting to know… is it C++ shared/wrapped code? Do you use Xamarin? You prefer each platform specific team working in their own silos?

PS: This post is revised version of my original blog post at Nintex Labs

Code and Slide Deck from YOW Connected 2014

This week I attended YOW Connected 2014, a mobile and IoT development conference in Melbourne, and also delivered a session. It was good to meet mobile developers in local community.

I delivered a talk “Write cleaner, maintainable and testable code in Android with MVVM”. I think it captured attention of some percentage of audience.

For those interested, code and slides are linked below:

and code has been pushed to GitHub

If you have any query related to talk, please feel free to contact me.

Java in Android is a variant of Java

Android app development uses Java platform and you can consume JDK (java development toolkit) in Android.

This above statement is partially true however the fact is that some part of Java SDK is being pulled out and packaged it in Android SDK. Second fact is that we can use Java language to consume Android SDK. However today, it is recommended to use Java 6 for Android projects. (I will come to answer that why)

Notice If you expand the android.jar you can view that it is composed of several different packages of open source libraries. So Android SDK is actually a collection of snapshot of several open source libraries at a particular time such as Java SDK/OpenJDK, Apache HttpClient, json.org, w3c dom etc. and of course the android core APIs and some of them are even uniquely modified for Android.

This all leads to an interesting question in the community I read some days ago on Reddit

Can we leverage Java 8 features in Android?

The answer is not yet.

Why? (you ask!)

Because remember we read that Android run on its own Dalvrik VM instead of Java standard VM (JVM) to convert byte code to executable.Therefore if any feature has been added in Java 8, its written to produce certain byte code by Java compiler which is then worked out by updated JVM. However that features needs to be supported in Dalvrik VM as well. Plus authors of Android needs to pull latest version of Java packages into the android.jar.

Hope this clears out confusion for some android developers!

Further readings:

  1. Java vs. Android APIs
  2. Will Android get Java 7 or 8 in a forseeable future?

Beginning Android 4 Book Review

Book Title: Beginning Android 4 Application Development
Author: Wei-Meng Lee
Publisher: Wrox

Mobile application development is all around these days and Android is one of the famous platform for smartphones. This title introduce reader to android development and it’s for best fit for beginners. 

Just to share a bit background here , I have been working on .NET/C# platform for almost 5+ years and so I was new to android/java/eclipse.

This book serves as a great boost to newbie by providing step by step, clear, practical examples and in full color screenshots. So the flow and example helps a lot in contrast to reading android API details online. The high level outline contains following topics:

  1. Introduction
  2. Getting Started with Android Programming
  3. Activities, Fragments and Intents
  4. Getting to know the Android User Interface
  5. Designing your user interface with views
  6. Displaying Pictures and Menus with Views
  7. Data Persistence
  8. Content Providers
  9. Messaging
  10. Location-Based Services
  11. Networking
  12. Developing Android Services
  13. Publishing Android Applications
  14. Appendix: Using Eclipse for Android Development
  15. Appendix: Using the Android Emulator

I would like to highlight that appendices are really helpful for readers who are new to eclipse IDE and android emulator.

However if you have little experience of android previously then you might not find this book satisfy your thirst for advance topics. And I think that there must be a section of guidelines for new mobile application development, so things like battery utilization, network usage optimization etc. But the book covers most commonly used APIs.

Bottom line: If you are new to android world, this book is a good fit for you. Go buy it. If you have step through initial ladders in android development this book might not be best fit for you. 

I would like to thank wrox for sending me a complimentary copy on request.

Android NetworkOnMainThread Exception

Hi folks,

Like me, if you are new to android platform and working with network requests such as using HttpRequest, HttpGet, or HttpPost etc. YOU may come across a “NetworkOnMainThread” exception or your application stopped responding. This really annoys in a way that your code complies nicely and smells like *it should work* but on runtime it throws an exception which result in application termination.

The other day I was working with RESTful services and was developing a sample code to send simple HttpPut request to my services and got this error.

Solution:

Most likely the root cause will be either you are calling some network activity on your main thread and it has restricted thread policy and/or your app does not have enough permission. It can be solved by taking following steps:

  1. In AndroidManifest, make sure your application has permission to access network/internet.

  2. Use AsyncTask to enable network request to run asynchronously on another thread. Following is the code snippet that demonstrates use of HttpPut request using AsyncTask

Disclaimer:The code below is not optimized to be used in production environment, it’s just a sample to give idea about the solution. All views expressed are mine only

This would solve the problem!

For further reading, I would suggest to go through an article on performance “Android Threads, Handlers, and AsyncTask – Tutorial