How to setup alternate entry point in Blackberry application?

瘦欲@ 提交于 2020-01-09 03:58:18

问题


How to setup alternate entrypoint in Blackberry Application.There will be 2 application

  1. UI Application
  2. Background Application: will run on autostart.

There is a blackberry knowledge center article about this, which I tried, and coded as follows. But on clicking the application icon, there is no response.

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

Class UI Application

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

Background Application

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

    }   
}

I configured Blackberry_App_Discriptor.xml according to this (edit) bad-link
Can any body help,where am going wrong.


回答1:


Try logging the value of args and (if not null) args[0] to see what's actually being passed into main(). It's likely a problem with your compilation process where the background module is not passing an argument (or not passing the correct value).

Also, try saving off your EntryPointForApplication instance into a static variable so that it maintains a reference (isn't garbage collected) and so that if the icon is clicked again from the home screen while it's already running, you don't start multiple instances of your app. For example:

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


来源:https://stackoverflow.com/questions/3921029/how-to-setup-alternate-entry-point-in-blackberry-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!