Porting Case: RLinks


This porting story represents a case where a direct port of the application was not feasible. The Android application used Android UI classes and paradigms, for which there are no direct counterparts in Nokia Asha software platform. Consequently, large parts of the application have been rewritten, with the focus on creating a UI similar to the original.

To demonstrate the challenges and practical porting considerations of a network-intensive utility application, a client for the social news service Reddit client was first developed for Android and then ported to Nokia Asha platform. The Android application was written from scratch, as few up-to-date Android productivity/social media applications exist as open source projects.

The user flow of the application was kept as similar as possible to illustrate the differences, at the same time striving for the best possible user experience with the standard components offered by the platform. A number of helper classes were included in order to match the functionality in its Android counterpart. Most of the parts related to the handling of data remained the same, but the parts related to UI management or application flow control were rewritten for the target platform.

Figure 1. RLinks for Android

Figure 2. RLinks for Nokia Asha

Topics discussed in this porting project include:
  • Asynchronously running HTTP operations.
    • Connecting to a JSON REST API.
    • Parsing and representing JSON data.
  • Storing user data in the permanent storage (RMS).
  • Handling basic display flows.
  • Creating user interfaces based on LCDUI Forms.
    • Retaining legibility on different color schemes.
  • Using custom interface items for a more customised UI appearance.
    • Applying custom font sizes.

Figure 3. Application architecture

The set of functionalities was intentionally kept small, so that it wouldn't contain functionality for logged-in users, but still enough to be a good starting point for porting to Nokia Asha.

The Android application supports the basic browsing of reddits (links posted in various categories of Reddit) and their comments. In the Nokia Asha port, the feature set was replicated and then extended to cover choosing category, user login, voting and commenting. User session data, including automatically keeping the user logged in, is maintained in the permanent storage (RMS).

A central part of the functionality is opening links in the web browser of the device. As not all Nokia Asha devices are capable of handling video links on the browser, the category "/r/videos" was removed from the Nokia Asha port.


Android devices generally have more memory available for application usage than Nokia Asha devices. Although memory also needs to be properly taken care of in Android, it is an even more a crucial subject for optimisation on Java ME platform.

For optimising memory use, the use of deep class structures, intermediate objects, and additional method calls are generally avoided when possible.

All view manipulation (adding and removing items in the views) is done in the dedicated system UI thread to allow the platform to take care of paint operations when it best sees fit. This also ensures the system responds to any touch events as quickly as possible. Threads were also utilised for potentially long-running background tasks, such as parsing JSON and creating display items.

View instances are stored in a cache built on WeakReferences. This enables the user to smoothly switch back to a previous view or browse between link items, as the views only need to be regenerated when the cache contents get garbage collected by the platform. It also makes sure the application will not run out of memory when lots of view and item instances are created. From the developer viewpoint, once the caching is put in place, it works transparently without extra effort.

Network operations

For running HTTP requests, a simple HttpClient class was implemented. Each HTTP operation is implemented as an instance of the HttpOperation class, which makes creating new HTTP-based operations very convenient and straightforward. The HttpClient by default takes care of managing a queue of the HTTP operations, pick operations for executing, run the actual HTTP requests, and asynchronously communicate the responses back to the callers via Listener interfaces.

The HttpClient is also capable of running simultaneous operations in a configurable number of threads. It is used for loading images, as well as retrieving comments and submitting user-created data.

As cookie handling is also something that needed to be implemented manually, a very crude approach (the most simple one that works) was taken: all cookies sent by the site are always saved and sent back in forthcoming requests, regardless of their specific properties. As all the requests made by the HttpClient are made into Reddit and its APIs, there are no security issues involved.

Any HttpOperation is launched by simply calling start(). The default implementation of start() enqueues the operation in the application-wide queue of HttpClient, where it will get executed when its turn comes. This is how an operation for loading an image is triggered in the class ImageLoader:

new ImageLoadOperation(url, new ImageLoadOperation.Listener() {
    public void imageReceived(String url, byte[] data) {
        Image image = defaultImage;
            try {
                image = Image.createImage(data, 0, data.length);
            catch (IllegalArgumentException e) {}
            catch (NullPointerException e) {}
            if (cache != null) {
                cache.put(url, image);
The simplest example of a HttpOperation could be that of ImageLoadOperation, which only needs to fetch and pass forward any data received from a static URL. In its bare essentials it looks like the following:
public final class ImageLoadOperation
    extends HttpOperation {
    public interface Listener {
        public void imageReceived(String url, byte[] data);
    private final String url;
    private final Listener listener;
    public ImageLoadOperation(String url, Listener listener) {
        this.url = url;
        this.listener = listener;
    public final String getUrl() {
        return url;
    public final void responseReceived(byte[] data) {
        finished = true;
        listener.imageReceived(url, data);

UX and UI Design

The topic of UI design and implementation is one of the biggest differences in how things are done in Nokia Asha as opposed to Android.

The approach chosen for this application could be called a "Hybrid", as it uses a combination of standard LCDUI Form views and custom view items based on the CustomItem class. The view items are essentially "micro-canvases", where the content is rendered programmatically in exactly specified pixel coordinates. Even though some boilerplate code is required in order to tweak the UI to one's liking, the approach is very flexible: it allows the creation of customisable user interface components, without losing the benefits the native Form-based views offer, such as the platform taking care of kinetic scrolling and drawing just the visible portion of the screen.

Read More and Download

The full implementation details including code snippets and full source code can be found in the project wiki.

Last updated 8 July 2013

Back to top