简体   繁体   中英

How to make a J2ME application run in Background?

I have a written a J2ME application which uses Bluetooth and search a file within the peer mobile and download it. I would like to make my application run in background , whenever I get a call , or message and later resume after few seconds , Has anybody worked on this please share your experience . Is there any way to run a Midlet in background ?

to set a j2me app to the background use the following in your midlet class:

          Display.getDisplay (this).setCurrent (null);

to get the screen back use the following:

          Display.getDisplay (this).setCurrent (myCanvas);

Where myCanvas is your canvas instantiation

R

ps You can still use a thread or timer to do things in the background while your midlet is hidden.

ps2: this does not work on all models. (Works on Nokia s60, SonyEricsson, but not on Nokia s40, Samsung and some others.

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 to come in Fore ground :-

public void toFront() {
display.setCurrent(previousDisplayable);
}

But be aware that it not supports every device.(Works on Nokia s60, SonyEricsson, but not on Nokia s40, Samsung and some others).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM