AppStars

Server-driven UI in 2006, years before it had a name

MIAD, our 2006 mobile SDK: native J2ME screens laid out from XML pages on any web server, with themes, offline pages in the jar and one jar for every phone. It powered B-Live Radio for Bacardi.

In 2006 a phone app was a jar file of well under 100 KB. Once it shipped, it was frozen. Every screen was drawn by hand in code, so changing a word, a colour or a menu meant a new build, a new round of handset testing and a new download for every user.

We built MIAD, short for "Mobile Internet Application Development", to change that. Its screens were written in an XML markup of ours called MML, fetched from any ordinary web server or bundled in the jar, and laid out as native, full-screen J2ME widgets on the phone. Clixo was the first branded app built on it. MIAD also powered B-Live Radio for Bacardi, which has its own post.

Not WAP: native screens from server markup

Phones already had a way to show server content. WML, the markup of WAP (1999), sent "decks" of cards to the phone's browser, which rendered them as browser pages: small text, underlined links and whatever the browser decided a form should look like. Nothing felt like an app.

MIAD took the other half of that idea. The server still sent markup, but the phone didn't hand it to a browser. Our client parsed it and built real app UI from it: full-screen, skinned widgets with branded images, bitmap fonts, highlight states, menus bound to the soft keys and alert dialogs, all drawn by our own code so they looked the same on every handset. The server decided what the screen held. The client decided how a native screen should look and behave.

Today this is called server-driven UI, and large consumer apps use it to change screens without an app-store release. In 2006 it was simply the only sensible way to change a phone app without shipping a new one.

The problem it solved

  • Static apps. No web view, no layout engine and no way to update screens after release.
  • Fragmentation. Screens from 128×128 to 240×320, and soft keys, OK and back keys that had different codes on every brand.
  • Data costs. Users paid by the kilobyte over slow GPRS, so every page fetch had to earn its place.
  • Who builds it. Brands wanted mobile apps, but mobile Java developers were scarce. Web designers were not.

Architecture

 phone: MIAD J2ME client                       any web server
  StartPage (from the jad) -- http:// --------> MML pages, forms, sessions
                           -- file:// --> pages and images inside the jar
  miPage: parse MML (nanoxml) -> widgets
     Text, TextBox, Button, CheckBox, RadioButton, Image,
     Rectangle, ScrollBar, Hidden, Shoutcast
  miTheme (Theme.mml): fonts, alert windows, buttons, highlight
  miCommandManager: soft-key menus     miAlert: alert/confirm/option
  miImageCache (reference counted)     miDevice: key and screen quirks
  miContentLoader: fetch queue, 30 s watchdog
  • One jar for every phone. The client found out at runtime which phone it was on and worked around known device problems, so one jar and jad could cover the devices. Per-resolution builds existed too, for phones that misreported their own screen size and to size the bundled artwork.
  • The start page is configuration. The first page came from a StartPage property in the jad. It could be a page in the jar or a URL, so the same client could be rebranded by changing a text file.
  • MIADServer. A small Java socket server of ours sat alongside ordinary web hosting for features that needed a live connection.

The engineering

A page is a document

This is the start page of B-Live Radio, the app we built for Bacardi, as shipped in the jar:

<PAGE color="000000">
    <MENU style="BLiveMenuStart"></MENU>
    <WIDGETS>
        <IMAGE file="file://HEADER.PNG"></IMAGE>
        <IMAGE file="file://LOGO.PNG" y="36"></IMAGE>
        <IMAGE file="file://START.PNG" x="37" y="152" action="BLiveMain.php"></IMAGE>
    </WIDGETS>
</PAGE>

Images marked file:// come from the jar, so the page opens instantly with no data charge. The start button's action is a relative address, so it fetches the next page from the app's own server. Positions could be numbers, CENTER, LEFT or RIGHT, or left out entirely, in which case widgets flowed down the page with the theme's default spacing.

Markup to native widgets

The page parser walked the WIDGETS element and built a native widget for each child. Each widget class knew how to create itself from its XML node:

if(a_widgetType.compareTo("BUTTON") == 0)
  widget = miWidgetButton.CreateFromXml(name, a_formName, a_formMethod, a_node, styleNode);
else if(a_widgetType.compareTo("TEXTBOX") == 0)
  widget = miWidgetTextBox.CreateFromXml(name, a_formName, a_node, styleNode);
else if(a_widgetType.compareTo("IMAGE") == 0)
  widget = miWidgetImage.CreateFromXml(a_node);
else if(a_widgetType.compareTo("CHECKBOX") == 0)
  widget = miWidgetCheckBox.CreateFromXml(name, a_formName, a_node, styleNode);
else if(a_widgetType.compareTo("RADIOBUTTON") == 0)
  widget = miWidgetRadioButton.CreateFromXml(name, a_formName, a_node, styleNode);
else if(a_widgetType.compareTo("SHOUTCAST") == 0)
  widget = miWidgetShoutcast.CreateFromXml(a_node, a_widgetsNode);
else if(a_widgetType.compareTo("BR") == 0)
  m_pageHeight += miTheme.GetInstance().GetVertSpace();

Forms worked the way web designers expected. Fields inside a form element carried the form's name and its GET or POST method, and a button submitted them. The parser also tidied up after the author: if a group of radio buttons had none selected, it selected one, because a form should never start in an impossible state. A server could reply with an ERROR document instead of a PAGE, and the client showed it on a themed error page.

Themes and skins

Look and feel lived in a theme file, also MML, so a brand could restyle an app without touching code. An excerpt from the default theme:

<BUTTONS>
    <OK x="39" y="46"> <!-- CONFIRM alert type -->
        <IMAGE file="file://miadButton.png"></IMAGE>
        <HIGHLIGHTIMAGE file="file://miadButtonHighlighted.png"></HIGHLIGHTIMAGE>
        <CAPTION font="small" color="FF000000" highlightColor="FF000000">Ok</CAPTION>
    </OK>
</BUTTONS>
<HIGHLIGHT thickness="1" color="FF0000"></HIGHLIGHT>
<DEFAULTVERTSPACE pixels="8"></DEFAULTVERTSPACE>
<DEFAULTIMAGE file="file://miadImageNotFound.png"></DEFAULTIMAGE>

Fonts were our own bitmap fonts in three sizes, so text looked the same everywhere instead of depending on each phone's system font. A missing image fell back to a default that always lived in the jar, so a bad URL never left a hole in the screen.

Local first, network second

Every address went through one loader. Pages in the jar loaded immediately. Everything else joined a fetch queue on a background thread, with a 30-second watchdog so a hung GPRS connection could never hang the app:

if(!a_page.regionMatches(true, 0, "file://", 0, 7))
{
  if(!a_page.regionMatches(true, 0, "http://", 0, 7)) // default to reside on server
    a_page = miTheApp.GetInstance().GetServerAddress()+a_page;
}
if(a_page.regionMatches(true, 0, "file://", 0, 7)) // page is in jar
{
  InputStream is = getClass().getResourceAsStream(a_page.substring(6, a_page.length()));
  a_contentLoaderEvent.ContentLoadedLocally(a_page, new DataInputStream(is));
}
else
{
  FetchEntry fe = new FetchEntry(a_page, a_mode, a_contentLoaderEvent);
}

That made offline work natural. A user could fill in forms and browse static pages in the jar with no connection and no charge, then choose when to send.

Staying inside the heap

Branded apps are image-heavy and 2006 phones had very little memory. Images went through a cache with reference counts. A page asking for an image already in memory got the same one, and an image was released only when the last page using it let go.

One binary, every keypad

Soft keys were the hardest fragmentation problem. MIAD asked the phone for each key's name and normalised it: "soft1", "soft 1", "softkey 1" and "left soft" all became the left soft key, and "select", "ok", "fire" and "navi-center" all became OK. Raw key codes were the fallback when a phone gave no name.

A short coda: a poker server

MIAD's site listed turn-based multiplayer games as a use. In 2007 we built MoGam, a C# server for multi-table Texas Hold'em and blackjack with phone clients over TCP. Its main design choice is still a good one: socket threads only read and write, and a single message pump feeds every message to the game, so game logic runs on one thread and never races itself. Hand ranking was written from first principles, and an admin console and a test client were built alongside it. Its wire encryption, RC4, was common then. We'd use TLS today.

Where AI fits

There was no AI in MIAD. The idea that carries forward is a generic client and a server that describes what to do. MIAD pages told a phone what to show. Today, MCP tool descriptions tell an AI assistant what a system can do and how to call it. In both, behaviour changes on the server without shipping a new client.

What it taught us

  • Build for the people who'll use the tool. MML was designed so web designers could build branded phone apps the way they built for the web, and we documented it for them.
  • Separate content, style and behaviour. Pages, themes and the client changed independently, which is why one client could serve many brands.

Why it still matters

Field apps whose forms change weekly, and platforms that serve many clients from one code base, still need what MIAD did: screens defined on the server, rendered natively, working offline and styled per customer. We build those as web and SaaS platforms and mobile and field apps. The Mobstar Games story has more from the era.

Bring us the hard problem.

A 45-minute discovery call with the engineer who'll build it.