Search code examples
push-notificationblackberry

Register two application from main function


I am developing application in which i have to register two listener from main function. Out of two, One is for registering push notification and other is for when notification comes, will display icon on notification bar and on click of that i have to launch application. I am doing some wrong in code, but dont know where please help me out.

public static void main(String[] args)
{
    // Create a new instance of the application and make the currently
    // running thread the application's event dispatch thread.
    //System.out.println("====main function===="+args[0]);
    System.out.println("====args.length==="+args.length);

    if(args.length > 0 && args[0].equals("BB_push") )
    {

        System.out.println("====IN IF====");

        theApp = new MyApp();       
        theApp.enterEventDispatcher();


    }else if(args.length == 1 && args[0].equals("gui"))
    {
        System.out.println("====IN 1 GUI===");
        // Create a GUI instance for displaying a DemoMessageScreen.
        // This will occur when this application is invoked by the
        // View Demo Message menu item.
        MyApp messageScreenApp = new MyApp();
        messageScreenApp.enterEventDispatcher();

    }
    else{

        MessageListDemoDaemon daemon = new MessageListDemoDaemon();

        // Register application indicator
        EncodedImage indicatorIcon = EncodedImage.getEncodedImageResource("img/indicator.png");
        ApplicationIcon applicationIcon = new ApplicationIcon(indicatorIcon);
        ApplicationIndicatorRegistry.getInstance().register(applicationIcon, false, false);
        ApplicationMessageFolderRegistry reg = ApplicationMessageFolderRegistry.getInstance();
        if(reg.getApplicationFolder(INBOX_FOLDER_ID) == null)
        {
            daemon.init();
        }
try
{
        daemon.enterEventDispatcher();
}catch (Exception e) 
{
System.out.println("======catch after daemnon even===="+e);

}

        // push notificationlistener===============
        BackgroundApplication backApp=new BackgroundApplication();
        register.registerBpas();
        backApp.setupBackgroundApplication();

        backApp.enterEventDispatcher();
    }

}

Solution

  • Try this -

    public static void main(String[] args)
    {
    
       if(args != null && args.length > 0 && args[0].equals("gui"))
         {
    
           //Main Screen 
    
        }
        else if(args != null && args.length > 0 && args[0].equals("Background1")) {
    
           //First background application
    
    
        }else{
    
           //Second background application 
    
        }
    

    On your BlackBerry_App_Descriptor.xml - 1. Application - mark - Auto run on startup and do not show app icon on home screen. 2. Alternate entry points - A). gui- uncheck - Auto run on startup and do not show app icon on home screen. B). Background1 - mark - Auto run on startup and do not show app icon on home screen.