欢迎来到Doc100.Net免费学习资源知识分享平台!
您的位置:首页 > 程序异常 >

blackberry后台运行有关问题

更新时间: 2014-01-05 02:42:44 责任编辑: Author_N1

 

blackberry后台运行问题
请教各位大牛

  blackberry的后台运行,能否像其他智能机那样,在切换程序时,不显示后台运行的程序。

  真正在后台运行!!

--参考方法--
a working code

BlackBerry_App_Descriptor.xml设置程序为自动启动
---------------------
import net.rim.device.api.system.Application;

class BackgroundApplication extends Application {
public static void main(String[] args) {
BackgroundThread.loggerInit();
BackgroundThread.log("main() loggerInit");
BackgroundThread.waitForSingleton().start();
}

public BackgroundApplication() {
}
}
---------------------
import net.rim.device.api.system.Application;
import net.rim.device.api.system.EventLogger;
import net.rim.device.api.system.RuntimeStore;

class BackgroundThread extends Application {
public static String appName = "BackgroundThread";
public static long GUID = 0xcf891935c91e1987L;
private ListenerThread myThread;

public BackgroundThread() {
myThread = new ListenerThread();
}

/******************************************************************************************
* BackGround waitForSingleton() - returns an instance of a listening thread
******************************************************************************************/
public static BackgroundThread waitForSingleton(){
log("waitForSingleton");
//make sure this is a singleton instance
RuntimeStore store = RuntimeStore.getRuntimeStore();
Object o = store.get(GUID);
if (o == null){
log("inited");
store.put(GUID, new BackgroundThread());
return (BackgroundThread)store.get(GUID);
} else {
return (BackgroundThread)o;
}
}

/******************************************************************************************
* start() - starts the custom listen thread
******************************************************************************************/
public void start(){
invokeLater(new Runnable() {
public void run() {
myThread.start();
}
});

this.enterEventDispatcher(); 
}
/******************************************************************************************
* customer listening thread that is an extention of thread()
******************************************************************************************/
class ListenerThread extends Thread {

public void run() {
log("ListenerThread running");
try {
for(int i=0;true;i++) {
sleep(5000);
log("ListenerThread sleep 5 seconds");
}
}catch(Exception e) {

}
}
}

/******************************************************************************************/
public static void loggerInit() {
EventLogger.register(GUID, appName, EventLogger.VIEWER_STRING);
log("LoggerInited");
}

public static void log(String value) {
EventLogger
.logEvent(GUID, value.getBytes(), EventLogger.ALWAYS_LOG);
}

}


--参考方法--
Uiapplication设置为module,然后requestforground设置为false即可。
上一篇:上一篇
下一篇:下一篇

 

随机推荐程序问答结果

 

 

如对文章有任何疑问请提交到问题反馈,或者您对内容不满意,请您反馈给我们DOC100.NET论坛发贴求解。
DOC100.NET资源网,机器学习分类整理更新日期::2014-01-05 02:42:44
如需转载,请注明文章出处和来源网址:http://www.doc100.net/bugs/t/13450/
本文WWW.DOC100.NET DOC100.NET版权所有。