首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > BlackBerry >

blackberry后台运行有关问题

2012-03-25 
blackberry后台运行问题请教各位大牛blackberry的后台运行,能否像其他智能机那样,在切换程序时,不显示后台

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即可。

热点排行