How to make a J2ME application run in Background?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 13:00:05

问题


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 ?


回答1:


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

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

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




回答2:


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).



来源:https://stackoverflow.com/questions/1157483/how-to-make-a-j2me-application-run-in-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!