【问题标题】:Blackberry - How to transfer data from background to main ui application黑莓 - 如何将数据从后台传输到主 ui 应用程序
【发布时间】:2012-07-20 15:14:13
【问题描述】:

我正在使用推送通知来显示通知。它通过备用入口点工作正常。后台应用程序将监听通知。当我单击通知时,我想在我的 UI 应用程序上打开一个特定页面。它是如何完成的?我尝试使用以下代码,但它总是会从起始页面加载 Ui。如果应用程序已经在运行,我如何加载特定页面。否则从开始页面加载 UI。我还想将一些值从后台应用程序传递给 UI 应用程序。

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

【问题讨论】:

    标签: blackberry push-notification


    【解决方案1】:

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

    您的应用程序(listed in your previous question)启动,并检查传递给它的参数,然后确定是在后台运行,还是作为普通 UI 应用程序运行。

    您可以添加 更多 参数。在上面的代码中,把它改成这样:

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

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

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

    ... 我在 App 类中添加了 setNumberOfNotificationsReceived() 方法和 App(String) 构造函数。这些只是例子。随心所欲地制作它们。

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

    【讨论】:

      猜你喜欢
      • 2023-03-09
      • 2011-02-15
      • 1970-01-01
      • 2010-11-08
      • 1970-01-01
      • 2011-08-13
      • 1970-01-01
      • 2010-12-30
      • 1970-01-01
      相关资源
      最近更新 更多