Tuesday, February 3, 2009

Developing mobile applications using Gear episode 5: Display a splash screen

During the first phase of a MIDlet's life, it's common to find a lot of setup code used to initialize resources, data structures, user interfaces and anything else will be required. In this case, it's a best practice to display a splash screen to inform the user that the application is not frozen but is starting up. With the release of version 1.2.0 of Gear Java Mobile Framework, we've included a consistent yet customizable implementation for this feature.

1 How to achieve it ?
To properly setup Gear SplashScreen, all you have to do is create some keys inside the JAD file:
  • "SplashScreenImage:" -> contains a string with the path to the desired background image
  • "SplashScreenText:" -> contains a string with the desired text
If you are developing your application inside Eclipse with MTJ plugin (former EclipseME), you can easily achieve this by opening the Application Descriptor tab and "Add" the two key-value entries.


If your development environment is a different one, you have to manually insert those keys inside your application's JAD file.

As long as there is at least one of the two keys inside your JAD file, Gear will display the SplashScreen, so if you don't want it, simply don't specify anything.

2 Writing initialization code
Now that the SplashScreen is enabled, all you have to do is to override a single method inside your MIDlet
protected void onMidletInitializationComplete()
and fill it with your custom initializzation logic. We encourage users to follow this practice to put setup code inside this function rather than into the GearMIDlet constructor so they can take advantage from SplashScreen avoiding user interface freezes.
Here is an example of a possible implementation:
protected void onMidletInitializationComplete() {
// Call some custom initializzation methods
initDatabase();
doSomeHeavyDutyWork();
initUserInterface();
// ... and finally show the user the UI
EventManager.getInstance().enqueueEvent(new DisplayWidget(this, LoginForm.class));
}

3 The result
Gear's SplashScreen can display an image background, text and comes with an animated throbber centered vertically and anchored to the bottom of the screen. This is a possible result obtained with it:


Unfortunately this screen-shot is just a static image and you can't actually see the spinning animation of the throbber.

2 comments:

Unknown said...

Hi there, i'm a user who using ur framework for developing some mobile application. I really appreciate that you guys have developed a amazing framework like Gear. But now i'm getting stuck with the alert, i've tried some ways to create a alert with command listener but failed. I don't know the ways to achieve you guys so i try my luck for posting a comment here and wish u guys can read it.If one of u guys read this comment by chance, please send me a emaill to: tuth2004@yahoo.com.
Thank you so much for reading and creating a amazing j2me framework

Subbu said...

good one ... thx for the post Mobile Applications