Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Using the same code base for developing desktop and mobile applications

I am planning to develop an application that is targeted for mobile and desktop platforms. Can I use the same code base to develop application that are targeted for mobile and desktop platforms. If I can't, how much of it can I re use to develop desktop and mobile apps?.

would appreciate if anyone can share their experiences in doing similar efforts.

— asked March 17th 2010 by Srinivas Chennamaraja
  • desktop
  • mobile

2 Answers

  • Desktop and mobile apps are quite different in how the user interface pieces work. In addition, user interface pieces aren't 100% compatible between the different mobile platforms, either. There are many pieces of code that work great on iPhone but crash Android.

    That said, here's a good strategy:

    Separate your code into UI (display logic), Business Logic, and Data Logic. Business Logic and Data Logic should be reusable for all platforms. Just include these files inside both your desktop and mobile projects.

    For the UI code, you'll either want separate files for each platform (iPhone, Android, iPad) or write separate blocks of code like this:

    if (Ti.Platform.osname == "android")
       { android_code_block }
    else if (Ti.Platform.osname == "iphone")
       { iphone_code_block }
       { ipad_code_block }

    How much of your code is reusable? It depends on your project. A project that has a lot of heavy back-end processes, lots of database access and logic, etc. will have more portable code. A project that's mostly front-end stuff, like a game with a lot of moving parts will probably require more platform-specific code.

    Note: Until the documentation is more complete here, figuring out what works on Android and what doesn't is pretty much trial-and-error. It's time-consuming and frustrating. But it beats learning the Android SDK and starting from scratch – probably by an order of magnitude.

    — answered March 17th 2010 by Mark Burggraf
  • We are working to address the Android deficiencies. If you do find crashes, please let us know.

    — answered March 17th 2010 by Don Thorp
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.