专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > BlackBerry

blackberry后台运行有关问题

发布时间:2010-05-30 19:39:18 文章来源:www.iduyao.cn 采编人员:星星草
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即可。
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: