2010-10-13 66 views
1

如何在黑莓Application.There設置備用入口點將爲2應用如何在黑莓應用程序中設置備用入口點?

  1. UI應用
  2. 後臺應用程序:將在自動啓動運行。

關於這個,有一個blackberry knowledge center article,我試過了,編碼如下。但是在點擊應用程序圖標時,沒有任何迴應。

class EntryPointForApplication extends UiApplication { 
    public EntryPointForApplication() { 
     GUIApplication scr = new GUIApplication(); 
     pushScreen(scr);   
    } 

    public static void main(String[] args) { 

     if (args != null && args.length > 0 && args[0].equals("background1")){ 
      // Keep this instance around for rendering 
      // Notification dialogs. 
      BackgroundApplication backApp=new BackgroundApplication(); 
      backApp.enterEventDispatcher(); 
      backApp.setupBackgroundApplication(); 

     } else {  
     // Start a new app instance for GUI operations.  
     EntryPointForApplication application = new EntryPointForApplication(); 
      application.enterEventDispatcher();   
     }   
    } 
} 

類UI應用

class GUIApplication extends MainScreen { 
    public GUIApplication(){   
     add(new LabelField("Hello World"));    
    } 
} 

後臺應用

class BackgroundApplication extends Application { 
    public BackgroundApplication() { 
     // TODO Auto-generated constructor stub 
    } 
    public void setupBackgroundApplication(){ 

    } 
} 

我配置Blackberry_App_Discriptor.xml根據本(edit) bad-link
任何機構的幫助下,我在哪裏走錯了。

+0

順便說一句,在底部你的第二個鏈接進入完全相同的URL作爲第一個鏈接 – 2010-10-13 05:57:09

回答

4

嘗試記錄args的值和(如果不爲null)args [0]以查看實際正在傳入main()的內容。在後臺模塊未傳遞參數(或未傳遞正確值)的情況下,這可能是編譯過程中的問題。

另外,嘗試將您的EntryPointForApplication實例保存到靜態變量中,以便它維護一個引用(不是垃圾回收),並且如果在主屏幕運行時再次從主屏幕單擊圖標, t啓動您的應用程序的多個實例。例如:

class EntryPointForApplication extends UiApplication { 

    private static EntryPointForApplication theApp; 

    public EntryPointForApplication() { 
     GUIApplication scr = new GUIApplication(); 
     pushScreen(scr);   
    } 

    public static void main(String[] args) { 

     if (args != null && args.length > 0 && args[0].equals("background1")){ 
      // Keep this instance around for rendering 
      // Notification dialogs. 
      BackgroundApplication backApp=new BackgroundApplication(); 
      backApp.setupBackgroundApplication(); 
      backApp.enterEventDispatcher(); 
     } else {  
     if (theApp == null) { 
      // Start a new app instance for GUI operations.  
      theApp = new EntryPointForApplication(); 
      theApp.enterEventDispatcher();   
     } 
     }   
    } 
} 
+0

Application.enterEventDispatcher()「正常情況下」將不會返回,所以: backApp.setupBackgroundApplication() ; backApp.enterEventDispatcher(); 是此解決方案的正確順序。 – Dan 2011-03-23 15:51:50

+0

感謝丹 - 我只是更新了代碼 – 2011-03-23 23:49:02

+0

沒有問題 - 甚至不記得我是如何到這個線程大聲笑 – Dan 2011-03-24 16:25:53

相關問題