2010-10-13 64 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

相关问题