黑莓 - 如何从后台数据传输到主界面的应用程序 [英] Blackberry - How to transfer data from background to main ui application

查看:161
本文介绍了黑莓 - 如何从后台数据传输到主界面的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

荫使用推送通知显示通知。通过备选入口点的正常工作。后台应用程序将监听通知。当我点击一个通知,我想我的UI应用程序中打开一个特定的页面。它是如何做?我试着用下面的code,但它总是支持从起始页面加载UI。我怎么能如果应用程序已经运行加载特定页面。否则加载从一开始页面的UI。此外,我想从后台应用程序的UI应用程序传递一些值。

{尝试
     ApplicationDescriptor [] = appDesc​​riptors
         codeModuleManager.getApplicationDescriptors(codeModuleManager.getModuleHandle(MYAPP));
     ApplicationDescriptor appDesc​​riptor =
         新ApplicationDescriptor(appDesc​​riptors [0],新的String [] {MYAPP});
     。ApplicationManager.getApplicationManager()runApplication(appDesc​​riptor);
}赶上(ApplicationManagerException E){
        e.printStackTrace();
}


解决方案

您的从后台将数据传输到主UI应用程序(字符串MYAPP)。

您的应用程序(一<一href=\"http://stackoverflow.com/questions/11555165/blackberry-alternate-entry-point-start-app-from-background-applicationon-push\">listed在你的previous问题)启动,并检查传递给它的参数,然后再决定是否在后台运行,或者作为一个正常的UI应用。

您可以再补充的更多参数。在上面的code,改变它的东西是这样的:

ApplicationDescriptor appDesc​​riptor =
     新ApplicationDescriptor(appDesc​​riptors [0],
                               新的String [] {MYAPP,4,FirstScreen});

然后,在你的的UIApplication 子类(例如,在App.java),你可以将其更改为

公共静态无效的主要(字串[] args)
{
    应用该app = NULL;    开关(args.length){
    案例2:
        //提供初始画面和数量的通知
        该app =新的App(参数[2]);
        app.setNumberOfNotificationsReceived(的Integer.parseInt(参数[1]);
        打破;
    情况1:
        //提供了刚才的通知的数量,而不是最初的网名
        该app =新的App();
        app.setNumberOfNotificationsReceived(的Integer.parseInt(参数[1]);
        打破;
    情况下0:
    默认:
        //没有参数..启动后台应用程序
        BackgroundApplication应用=新BackgroundApplication();
        app.setupBackgroundApplication();
        该app =应用;
        打破;
    }    theApp.enterEventDispatcher();
}

...在那里我已经添加了 setNumberOfNotificationsReceived()方法和应用程序(字符串)构造函数你的应用类。这些仅仅是例子。让他们任何你想要的。

App.java:

公共应用程序()
{
    //按屏幕上的UI栈进行渲染。
    pushScreen(新DefaultScreen());
}公共应用程序(字符串屏幕名){
    如果(screenName.equalsIgnoreCase(FirstScreen)){
        pushScreen(新FirstScreen());
    }其他{
        pushScreen(新DefaultScreen());
    }
}

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

解决方案

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

这篇关于黑莓 - 如何从后台数据传输到主界面的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆