Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
493 views
in Technique[技术] by (71.8m points)

java - How to setup alternate entry point in Blackberry application?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...