I need my J2ME app to run in the background and still allow the user to use his mobile without problem. the app still needs to process some events in the background.
A device's ability to run an application in the background depends on its ability to multitask. Therefore, more expensive, PDA-type devices are more likely to support background execution than lower-cost devices. For in background :-
private Display display = Display.getDisplay(this);
private Displayable previousDisplayable;
public void toBack() {
previousDisplayable = display.getCurrent();
display.setCurrent(null);
}
And foreground :-
public void toFront() {
display.setCurrent(previousDisplayable);
}
But Be aware that every device not supports that features.(Works on Nokia s60, SonyEricsson, but not on Nokia s40, Samsung and some others).
Running a midlet in the background but still processing is not specified in the j2me standard i think. Normaly at the moment your midlet is moved to background the paused method should be called.
But not every vendor implements it that way. Symbian keeps your program running as if there was no change when minimized. At least on the N80 and N90.
This is not always supported, but on the handsets that do, the command is:
Display.getDisplay(theMidlet).setCurrent(null);
MIDlet.notifyPaused()
If you app is in background then it doesn't receive any events. So I don't know how it can process any event in the background. If its a preload J2ME app then you can work with the handset manufacturer and obtain certain jad attributes to put your midlet in background. You can thus not allow the user to exit the app. You may want to think this use case through.
On the other hand you can do all these in Blackberry apps.