Blackberry - How to transfer data from background to main ui application

风流意气都作罢 提交于 2019-12-11 09:39:15

问题


Iam using push notification to show notification. Its working fine by Alternate Entry point. Background application will listen for notifications. When I click on a notification, I want to open a specific page on my UI application. How is it done? I tried using the following code, but it will alway load the Ui from the starting page. How can I load a specific page if the app is already running. Else load the UI from the begining page. Also I want to pass some values from the Background app to the UI Application.

try {
     ApplicationDescriptor[] appDescriptors = 
         CodeModuleManager.getApplicationDescriptors(CodeModuleManager.getModuleHandle("MYAPP"));
     ApplicationDescriptor appDescriptor = 
         new ApplicationDescriptor(appDescriptors[0], new String[] {"MYAPP"});
     ApplicationManager.getApplicationManager().runApplication(appDescriptor);
} catch (ApplicationManagerException e) {
        e.printStackTrace();
}

回答1:


You are already transferring data from the background to the main UI Application (the string "MYAPP").

Your application (the one listed in your previous question) starts up, and checks the arguments passed to it, and then determines whether to run in the background, or as a normal UI Application.

You can just add more arguments. In the code above, change it to something like this:

ApplicationDescriptor appDescriptor = 
     new ApplicationDescriptor(appDescriptors[0], 
                               new String[] { "MYAPP", "4", "FirstScreen" });

Then, in your UiApplication subclass (e.g. in App.java), you can change it to

public static void main(String[] args)
{
    Application theApp = null;

    switch (args.length) {
    case 2:
        // initial screen and number of notifications provided
        theApp = new App(args[2]);
        app.setNumberOfNotificationsReceived(Integer.parseInt(args[1]);
        break;
    case 1: 
        // just the number of notifications was provided, not an initial screen name
        theApp = new App();
        app.setNumberOfNotificationsReceived(Integer.parseInt(args[1]);
        break;
    case 0:
    default:
        // no arguments .. launch the background application
        BackgroundApplication app = new BackgroundApplication();
        app.setupBackgroundApplication();
        theApp = app;
        break;
    }

    theApp.enterEventDispatcher();
}

... where I've added the setNumberOfNotificationsReceived() method and the App(String) constructor in your App class. Those are just examples. Make them whatever you want.

App.java:

public App()
{        
    // Push a screen onto the UI stack for rendering.
    pushScreen(new DefaultScreen());
} 

public App(String screenName) {
    if (screenName.equalsIgnoreCase("FirstScreen")) {
        pushScreen(new FirstScreen());
    } else {
        pushScreen(new DefaultScreen());
    }
}


来源:https://stackoverflow.com/questions/11582112/blackberry-how-to-transfer-data-from-background-to-main-ui-application

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