我創建的應用程序,哪些用戶可以從菜單和從圖標開始。我不在我的應用程序中使用GlobalEventListener,只需註冊ApplicationMenuitem。現在我得到錯誤:先前的實例在啓動我的應用程序時仍然處於活動狀態。以前的實例仍然在黑莓的活動錯誤
重現步驟沒有那麼簡單:
推出的應用程序從圖標
不要關閉它,只需切換到另一個應用程序從圖標
啓動應用程序再次
我成立於article in bla ckberry的論壇,但我找不到解決方案,我應該刪除我的ApplicationMenuItem:它添加到手機啓動,應該顯示所有的時間。
我的代碼:
public class Jingu extends UiApplication {
public static void main(String[] args) {
ApplicationManager app = ApplicationManager.getApplicationManager();
boolean keepGoing = true;
while (keepGoing) {
if (app.inStartup()) {
try {
Thread.sleep(1000);
} catch (Exception e) {}
} else {
keepGoing = false;
}
}
Jingu theApp = new Jingu();
theApp.initMenuItem();
theApp.showMainScreen();
theApp.enterEventDispatcher();
}
public Jingu() {
}
public void showMainScreen() {
showScreen(new JinguMainScreen(this));
}
public void initMenuItem() {
// Create menu item
Object o = RuntimeStore.getRuntimeStore().get(JinguMenuItem.MY_MENU_ID);
// register only if not done already.
if (o == null) {
new JinguMenuItem(this).registerInstance();
}
}
public void showScreen(Screen aScreen) {
synchronized (Application.getEventLock()) {
try {
UiApplication.getUiApplication().popScreen(aScreen);
} catch (Exception e) {
}
UiApplication.getUiApplication().pushScreen(aScreen);
}
}
}
public class JinguMenuItem extends ApplicationMenuItem {
public static final long MY_MENU_ID = 0xb9739d5240d5943dL;
private final Jingu jingu;
public JinguMenuItem(Jingu jingu) {
super(0x350100);
this.jingu = jingu;
}
public void registerInstance() {
Object menuItem = RuntimeStore.getRuntimeStore().remove(MY_MENU_ID);
if (menuItem == null) {
ApplicationMenuItemRepository amir = ApplicationMenuItemRepository.getInstance();
amir.addMenuItem(ApplicationMenuItemRepository.MENUITEM_SYSTEM, this);
RuntimeStore.getRuntimeStore().put(MY_MENU_ID, this);
}
}
public Object run(Object context) {
jingu.setDefaultFont(Font.getDefault());
jingu.setMainApp(false);
jingu.setBbmEditField(null);
jingu.showMainScreen();
return context;
}
public String toString() {
return "My Menu";
}
}
PLZ建議,我應該在我的應用程序刪除ApplicationMenuItem?
我的問候,
瓦迪姆
至於評論第2步:我發現切換應用程序實際上會在默認情況下關閉您的應用程序,因此它與打開關閉基本相同,也只關閉屏幕,因此調用onClose()。您需要覆蓋屏幕類的onClose(),而不是將其發送到背景。 – clauswey 2011-04-14 17:02:21