Blackberry Simulator is a Time-Burglar?


Blackberry has done an excellent job designing the Blackberry simulators that come with the Eclipse plugin. Testing and debugging is really a breeze once the simulator is running. The only problem I have with the tools that Blackberry supplies is the length of time it takes for the simulator to start. I'm not running the tools on a slow machine either - My setup is a new Mac Mini - 2 GHz Intel Core 2 Duo - with upgraded 7200RPM hard drive and 4GB of RAM, running Windows 7 64-bit in the Bootcamp partition. Although I have VMWare fusion on Leopard, I still boot directly into Windows 7 since Fusion seems to run Win7 pretty slow.

I timed the startup of the simulator and it takes a full 35 seconds to boot the device to the home screen while it takes 55 seconds with the debugger attached. Unfortunately, you cannot load changes to the code dynamically into the simulator - at least I haven't been able to find a way to do this. So you know what this means - every time you want to test your code you have to wait 35-55 seconds for the simulator to start then locate your program in the device and click it to run.

To make matters worse, the close button on the simulator doesn't function and you cannot easily start a new simulator when one is running. The only solution is to keep the Windows task manager open at all times and use it to shut the simulator down. I did some investigation when I first started programming for Blackberry and haven't found a solution for this issue anywhere.

It may seem that I'm complaining about something minor but when you stop and think about the time waste of sitting and waiting for the simulator to start over the course of developing an app, those chunks of 35-55 seconds really start to add up. While programming it's common for me to run the simulator 5-10 times an hour. Staying on the conservative side, lets say 5 times an hour - 5 x 35 /60 means you're wasting almost 3 minutes each hour sitting and waiting for the simulator to start. Multiply this x 10 hrs of work each day means 30 minutes of your time is wasted each day doing nothing - just twiddling your thumbs waiting for the simulator.

Given these estimates, I'd say that on the last application I wrote a full day(24 hours) was wasted waiting for the simulator and that's not even counting the extra time it takes for the debugger to start! The only thing you can do to speed up startup each time is to escape the Setup Wizard when you first run the simulator of choice, or for every simulator you use. This will prevent the Wizard from running saving you a few seconds. Unfortunately, my timing of startup includes this "optimization" so don't expect anything faster.
Once the backend and UI of the application are complete and have been thoroughly tested you'll eventually want to design a unique application icon for provisioning onto the device. If you do not assign an icon to your app, the device assigns a cookie-cutter application icon which does a pretty poor job of distinguishing your app. If you intend on programming your app for all the various OS versions beyond 4.5 you'll need to design the icon for both the Precision and Dimension themes. Regardless of what icon you come up with you'll need to have one regular version and one that displays the "rollover" effect.

In order to programmatically instantiate the rollover effect for OS's prior to 4.7 you must first set your app to startup with the Blackberry OS and then you have to create an alternate entry point for the application such that the OS can access your app on startup and acquire the appropriate icon images to use in creating the effect. Although I've never tried this, apparently for 4.7 you can just set the Icon and Focus Icon files straight in the Project properties by right-clicking on the project then "Properties->Blackberry Project Properties-> Resources". Then just add the icon files to the appropriate slots. Even though 4.7 has this capability, I still find that since most developers are working across multiple OS's it makes much more sense to programatically work this functionality into your application.


I'll show the required steps for Eclipse with the Blackberry plugin since this is my environment of choice. Some of the code is located in the Blackberry knowledge base articles found here

Configure the Eclipse Project Properties


First you need to configure your project to run when the Blackberry device is started. Right click the project file and go to Properties->Blackberry Project Properties. Check the 'System Module' and 'Auto-run on startup' checkboxes and make sure the'Startup Tier' is set to '7(Last;3rd party apps only'. The config for your main project should look like the one below:



Next you'll need to create a new Blackberry project in the same workspace as the current project. The purpose is to act as a surrogate that passes the appropriate command line information to our main app when it's compiled. Once this is complete, right-click the project file as before and go to "Properties->Blackberry Project properties'. Set the Project type as 'Alternate CLDC Application Entry Point', the 'Argument passed to "static public void main(String args[])" as "gui" and "Home screen position" as 0. The "Alternate entry point for:" option should be set to your main project name. Refer to the screenshot below:



[Update]In order to set a custom application icon after installation of your app simply right-click this new Project and browse to Project properties->Blackberry Project Properties->Resources(tab) then under the "Icon Files" option click "Add" and point to the proper .png file you want as your base application icon. Make sure that .png file is in your main project's directory otherwise it won't be included in your .cod file and the phone won't have the image to load after install.

After you complete the coding below and recompile your project, open your .jad configuration file you'll see the following line in it indicating the icon file to use:

RIM-MIDlet-Icon-2-1: ../{MAIN_PROJECT_DIRECTORY}/src/{PNG_FILE_NAME}.png,

I haven't tried directly modifying this path to the image in the main project's .jad file but I imagine that it would work and would be quicker. Note that the rollover effect will not work until the phone is reset however without making this modification you'll get the default Blackberry icon for your app which could be a bit confusing to the end user.[END UPDATE]


Coding the Alternate Entry Point


The final step is to code the alternate entry point into your main function. The idea here is that you've set the Launcher project settings to pass the "gui" string on the command line which will tell our application to run when the user selects our app normally. If our application doesn't receive the "gui" string - in this case when the Blackberry is started up - it will instead provide the OS with the appropriate icon files to perform the rollover effect. Here's the code for main:


public static void main(String[] args){

if ( args != null && args.length > 0 && args[0].equals("gui") ){
//main entry point
MainScreenUI theApp = new MainScreenUI(false);
theApp.enterEventDispatcher();
} else {
//Pass the icons
MainScreenUI theApp = new MainScreenUI(true);
theApp.enterEventDispatcher();
}

}


To reinforce the point here we are passing our MainScreenUI constructor a boolean that will tell it if it's received the "gui" string from the command line - true for normal user startup and false if the phone rebooted/turned on. Below is the code in MainScreenUI for the class constructor - note that the boolean autoStart tells the constructor what to do during runtime. Also, we're using the HomeScreen class to see what the preferred icon size is and then based on that will identify the correct icon to use. The BitMaps that are used to pass to HomeScreen.UpdateIcon() and HomeScreen.setRolloverIcon() must be final since we're calling final functions. Refer to the code below :

public MainScreenUI(boolean autoStart){

if(autoStart){
//The application started using the auto start entry point.
//Setup the rollover icons.

Bitmap tRegIcon;
Bitmap tIcon;
//73 Storm, 80 Bold,
if(HomeScreen.getPreferredIconHeight() > 70){
tRegIcon = Bitmap.getBitmapResource("iconpng.png");
tIcon = Bitmap.getBitmapResource("iconglowpng.png");
}
else{
tRegIcon = Bitmap.getBitmapResource("curve.png");
tIcon = Bitmap.getBitmapResource("curveglow.png");
}

final Bitmap regIcon = tRegIcon;
final Bitmap icon = tIcon;

invokeLater(new Runnable()
{
public void run()
{
ApplicationManager myApp =
ApplicationManager.getApplicationManager();

boolean keepGoing = true;

while (keepGoing)
{
//Check if the BlackBerry has completed its startup process.

if (myApp.inStartup())
{
//The BlackBerry is still starting up, sleep for 1 second.

try
{
Thread.sleep(1000);
}
catch (Exception ex)
{
//Couldn't sleep, handle exception.
}
}
else
{
//The BlackBerry has finished its startup process.

//Set the rollover icons.
try{
HomeScreen.updateIcon(regIcon, 1);
HomeScreen.setRolloverIcon(icon, 1);

}
catch(Exception e){}

keepGoing = false;
}
}
//Exit the application.
System.exit(0);
}
});
}

else{
TitleScreen ts = new TitleScreen();
pushScreen(ts);
Thread t = new Thread(this);
t.start();
int width = Display.getWidth();

............



Note that the try{}catch{} block is required around the HomeScreen.updateIcon() and HomeScreen.setRolloverIcon() since for reasons unknown to me(a bug in the OS code perhaps?) an IllegalArgumentException is thrown there. Despite this, the functions still work and your icons will appear.

Now you'll be able to compile your application as normal and test on the Blackberry device. Upon startup, the correct icon files will be inserted by the OS and when the user scrolls onto it the rollover will place the appropriate icon in place.
top