Devices are a pain, every device has its own oddities and trying to figure out what went wrong through guesswork is just not very productive.
I said before that supporting all devices isn't feasible in my opinion, but still we want to support as much as possible or at least know why we don't work on a given device. Sometimes getting a device to work isn't the easiest thing in the world, the application might crash right before we even started experimenting.
We might not have enough information about the device in general in order to determine if its even applicable.
So here are general preliminary guidelines of "what to do" when a device doesn't even start LWUIT and how to debug that particular scenario and maybe help us get onto yet another device...
First off start with measuring the device capabilities to see if LWUIT can feasibly run on the given device, we didn't have much luck so far with devices that have less than 2mb of memory so while these might work (especially if the screen size/bit depth is smaller than 320x240x24) there is no telling.
Try running a hello world on the device, if the hello world MIDlet works build upwards from that point. Make sure your hello world looks something like this:
public class LWUITMIDlet extends MIDlet {Notice that I catch and display exceptions within the MIDP hi level API which should work on most devices and allow you to report the exception that occurred and maybe even track it down.
protected void startApp() {
try {
Display.init(this);
Display.getInstance().callSerially(new Runnable() {
public void run() {
try {
new Form("Hello").show();
} catch (Exception ex) {
ex.printStackTrace();
javax.microedition.lcdui.Form oops = new javax.microedition.lcdui.Form("Internal");
oops.append(ex.toString());
javax.microedition.lcdui.Display.getDisplay(this).setCurrent(oops);
}
}
});
} catch (Exception ex) {
ex.printStackTrace();
javax.microedition.lcdui.Form oops = new javax.microedition.lcdui.Form("Exception");
oops.append(ex.toString());
javax.microedition.lcdui.Display.getDisplay(this).setCurrent(oops);
}
}
protected void pauseApp() {
}
protected void destroyApp(boolean arg0) {
}
}
I also chose to execute everything possible on the LWUIT EDT thread to prevent potential race conditions or anything "funky", this is the simplest possible approach but we can obviously go deeper.
Try obfuscating code if the default doesn't work, some devices actually treat obfuscated code "better" (make sure to use progruard 4, other versions have some issues) mostly because of package scoping issues on some devices.
Ideally this should work or at least give some form of error which you can report, if it doesn't then you probably need to get into LWUIT's code which is a whole other blog post. From this point on just start adding application functionality until you can identify the source of your issue with the specific device.
Once you get running on a device but have issues within a specific device (that don't reproduce in emulator/simulator) logging is your best solution but this is an issue for another post.
No comments:
Post a Comment