如何在Blackberry应用程序中设置备用入口点?

时间:2010-10-13 05:33:34

标签: java blackberry entry-point alternate

如何在Blackberry Application中设置备用入口点。将有2个应用程序

  1. UI应用程序
  2. 后台应用程序:将在自动启动时运行。
  3. 有一个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(){
    
        }   
    }
    

    我根据此(edit) bad-link配置了Blackberry_App_Discriptor.xml
    任何身体都可以帮助,哪里出错了。

1 个答案:

答案 0 :(得分:4)

尝试记录args的值和(如果不是null)args [0]以查看实际传递给main()的内容。编译过程中可能存在问题,即后台模块未传递参数(或未传递正确的值)。

另外,尝试将EntryPointForApplication实例保存到静态变量中,以便它维护一个引用(不是垃圾回收),这样如果在主屏幕已经运行时再次单击该图标,则不会启动应用的多个实例。例如:

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();         
         } 
       }        
    }   
}