Appcelerator Blog

The Leading Resource for All Things Mobile

Forging Titanium Episode 6: A Single Context Tabbed Application Template

0 Flares 0 Flares ×
Editor’s note: This and future episodes of Forging Titanium are available here. In this week’s episode, we’ll be taking a look at how to implement a tab-based application in a single JavaScript context in Titanium Mobile. Throughout our reference guides and official training course, we generally advocate the use of a single JavaScript context in your Titanium applications. However, in our most popular demo application, the Titanium Mobile Kitchen Sink, a tab-based application is developed using multiple contexts by associating each window opened with a URL to a JavaScript file. While this approach is technically valid, it presents the developer with difficulties around sharing data between windows, confusion around when code for a window has been executed, possible object reference issues which can lead to memory leaks, and reloading of JavaScript code in every window for shared libraries. For those reasons, unless you have a specific need for a “clean slate” in every window, using multiple JavaScript contexts cannot be considered a best practice approach to structuring a Titanium Mobile application. What then would be a reasonable approach to structuring windows in a tabbed application? And how do we work around the loss of Ti.UI.currentTab and friends? Find out the answer in this week’s episode of Forging Titanium. Episode Resources:
0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×


  1. David Geller

    I definitely need to learn more about this at Codestrong. If I understand the tutorial – the way KitchenSink lays out windows – and the way all the prior documentation suggests – the way I do it in my app – is now not recommended. This is definitely not making the programmer’s job easy.

  2. This seems like a hack, If the best practice has changed then maybe the Tab system in Titanium should be reengineered to reflect it or a new tabbed group should be created just using views and not windows.

  3. I came, I read this article, I cnouqreed.

  4. I tried this and it worked on iPhone but not on android:


    Wrapped java.lang. IllegalArgumentException: size must be >= 0

    And the line that rows the error are the require(‘lib/require_patch).monkeypatch(this);

  5. Okey, thank you so much for the response on this :)

  6. Hi,

    Is the Monkey Patch required anymore on the newest version of Titanium SDK (1.8)? I found the following thread, but I’m unsure of the last response and overall outcome / latest recommendations.

    Thank you,

    • Kevin Whinnery

      No, that patch is no longer needed. Titanium’s module implementation noew supports direct assignment to the module.exports object for instantiable types, and caches modules so that you’re not reloading JavaScript over and over.

  7. Adriano

    Dear Kevin,

    with 1.8 SDK, on Android it throws an error:

    Uncaught ReferenceError: globals is not defined

    I know that there’s no global context with 1.8, but how can I overcome it in my app?




  8. Kevin,

    Thanks I was able to get that Template.Tabbed working. How would you recommend using “globals” in that template?

  9. Kevin Whinnery

    Global variables are no longer supported in commonjs modules in 1.8 – check this guide for some thoughts on alternative approaches:

  10. From the API “A heavyweight window is always created when you open a new window from inside a TabGroup.

    A heavyweight window is associated with a new Android Activity. Creating a heavyweight window always creates a new JavaScript context.”

    So when we tap a tab does it not create new javascript context?

    • Kevin Whinnery

      @Nimish a couple things – this template is out of date – check out the new tabbed application template in Titanium Studio. With very few exceptions, unless you open a window which points to a JavaScript file in the “url” property, your code will be executing in a single context.

  11. Lucky enough I decided to read the comments. Unlucky cause I’ve spent quite a bit of time to actually develop with the old approach, app works on an iPhone, now that I’m transitioning to Android, it has broke. Have to figure out a way to port the code now to the new way things work.
    Kevin, please make a newer video tutorial, and remove the old ones. You’re killing newcomers to Appcelerator like this. This has gotten superconfusing. I think you should clean up both the documentation(wiki) and the videos. Like you’ve done with warning everywhere about “KitchenSink” that people shouldn’t structure their app in that way.

  12. Kevin Whinnery

    @Methemer sorry, five months can be a long time in an open source project, so these types of tutorials can become out of date. In next week’s Forging Titanium episode I will be going over the new app templates in Studio, which you can see either by creating a new project in Studio or going here:

    And looking at the Template.* repos.

    While there’s no way we can go back and redo every video tutorial we’ve done or will do, I will put a link on the video pages to indicate there’s newer information available. Thanks…

Comments are closed.

Sign up for updates!

Become a mobile leader. Take the first step to scale mobile innovation throughout your enterprise.
Get in touch
computer and tablet showing Appcelerator software
Start free, grow from there.
0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×