您已经将数据从后台传输到主 UI 应用程序(字符串"MYAPP"
)。
您的应用程序(在上一个问题中列出的应用程序)启动,并检查传递给它的参数,然后确定是在后台运行,还是作为普通 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();
}
...我在你的类中添加了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());
}
}