Porting Android (Java) applications to Java ME on S60 5th Edition
Android is a platform for mobile devices maintained by Google and supported by the Open Handset Alliance.
The Android platform includes an application framework, an operating system, a Java Virtual Machine called Dalvik, a web browser based on WebKit, SQLite database, middleware services and key applications.
The Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language. However, the Java APIs supported by Android are not standar Java ME APIs (JSRs), so in order to develop an Android application the developer must learn and cope with many new APIs.
Android is built on the Linux Kernel and utilizes a custom virtual machine, commonly referred as Dalvik VM. Although the Android's kernel is based on Linux, developers can only use Java programming syntax to develop Android applications.
Java Micro Edition applications are not compatible with Android due to the new format of bytecodes used by Dalvik virtual machine and due to this fact developers must rewrite Android applications to work on S60 5th Edition devices or any other devices supporting standard Java ME.
This articlpe provides an overview of Android in an extent that will allow you to port Android applications to S60 5th Edition, focusing on Java ME.
Android platform - Architecture
Android architecture is basically divided into several components: Application Framework, Libraries, Android Runtime and Linux Kernel.
As mentioned before, Android has virtual machine called Dalvik and every Android application will run on its own process, that is, using its own instance of Dalvik JVM.
The Dalvik JVM runs files called Dalvik executables (.dex files), a kind of Java bytecode optimized for the Android platform. The Linux Kernel is based on version 2.6.
At last, Android code can use the 1.5 version of Java language (Tiger), so the Tiger features are available for Android.
The main components of an Android application are: Activity, IntentReceiver, Service and ContentProvider. Depending on the kind of application one might be developing, not all components will be present in an application. In short, they are defined as below:
- An Activity has the main callback methods and is linked (represents) a blank screen in a logical way (an application may have several Activity classes);
- An Intent represents an action and it is composed by <action> and <category> XML elements. Then the IntentReceiver and IntentFilter (<intent-filter> element) will take care of its action processing and guarantee that the right Intent will be processed;
- AndroidManifest.xml - the components above are controlled by means of the AndroidManifest.xml configuration file, that is a kind of descriptor for the Android application.
The main components are the android.view.View and android.view.ViewGroup.
- The View represents a graphical area on the device's screen and by means of it you can find out the width and height, set focus, control scrolling and key handling for the correspondent area. It is very extensible and several Android Widgets extend from View.
Some examples of Widgets are AbsListView, AbsSeekBar, AbsSpinner, AppWidgetHostView, AutoCompleteTextView, Button, CheckBox, CheckedTextView, Chronometer, CompoundButton, DatePicker, DialerFilter, DigitalClock, EditText, ExpandableListView, ExtractEditText, FrameLayout, GLSurfaceView, Gallery, GridView, HorizontalScrollView, ImageButton, ImageSwitcher, LinearLayout, ListView, MediaController, MultiAutoCompleteTextView, RadioButton, RadioGroup, RatingBar, RelativeLayout, ScrollView, SeekBar, SlidingDrawer, Spinner, TabHost, TabWidget, TableLayout, TableRow, TextSwitcher, TimePicker, ToggleButton, TwoLineListItem, VideoView, ViewAnimator, ViewFlipper, ViewSwitcher, WebView, ZoomButton and ZoomControls.
- The ViewGroup is a container of View, that is, it is a container class and helps defining the layout characteristics of your GUI.
Some examples of layouts are AbsoluteLayout, FrameLayout, LinearLayout and RelativeLayout.
Project Structure and Coding Style
XML files play a major role in android application development, mainly regarding configuration and declaration of resources. But standard Java ME does not use the same approach, so the mapping that is done using the AndroidManifest.xml (events mapping to actions) do not exist in Java ME by default. You will need to analyze the Android manifest and implement the logical mapping on your S60 Java ME application using well known patterns like MVC, Command, Dispatcher and others.
Just as an example, when developing an Android application, in order to create the GUI, navigation mapping and action linkage generally the developer uses some XML files and refer each component using its ID. In standard Java ME as available in S60 devices, there is no such mapping imposed by the platform so one should refer each component by name and instance reference, using its source file (class definition) itself.
Below we have a very basic project structure regarding an Android project:
- The src folder is where your all the classes created explicitly by the developer will be located. You can see a basic Activity class in this folder, inside the com.forum.nokia.android.to.s60 package;
- The gen folder has several classes that are created automatically by Android and should never be edited manually by the developer;
- The android.jar that is included on the classpath and has the Android framework;
- The res folder that contains all the resources used by the application, such as images (drawable subfolder has icon.png file), layouts (layout subfolder has the main.xml file, defining the layout for GUIs), static values, kind of resource bundle (values subfolder has the string.xml file where declarative values will be declared);
- AndroidManifest.xml - as cited before, it is the main configuration file for the Android application.
To get details description about each classes you can refer docs available for both platform. Generally APIS which is used for business logic are similar. It uses the concept of activity and intent which we can port into our platform's event architecture and APIs provided by it.
API Similarities and Difference
The following java packages is not available in android which is so similar to J2ME as most of it is not included in j2me too by considering the small devices limitation.
Nokia - Jad, Jar
Android - .apk(using Ant)
Nokia supports: VeriSign, thawte, Java Verifed Certificate etc
Android supports: by private key ( Tools like Keytool and Jarsigner)
Permission of Resource
In android the developer need to set permission in the manifest file of android project to let the application or user to access the resource while in j2me if application is not sign then application will ask the permission to user while executing it and by signing it will be secure so there is no need of permission confirmation for most of the resource.
Data Storage on device
J2ME : RMS
android : SQLite database.