BlackBerryアプリケーションで代替エントリポイントをセットアップする方法は?
-
29-09-2019 - |
質問
BlackBerryアプリケーションで交互のエントリポイントをセットアップする方法。2つのアプリケーションがあります
- UIアプリケーション
- バックグラウンドアプリケーション:AutoStartで実行されます。
があります BlackBerry Knowledge Centerの記事 これについて、私が試してみて、次のようにコーディングしました。しかし、アプリケーションアイコンをクリックすると、応答はありません。
class EntryPointForApplication extends UiApplication {
public EntryPointForApplication() {
GUIApplication scr = new GUIApplication();
pushScreen(scr);
}
public static void main(String[] args) {
if ( args != null && args.length > 0 && args[0].equals("background1") ){
// Keep this instance around for rendering
// Notification dialogs.
BackgroundApplication backApp=new BackgroundApplication();
backApp.enterEventDispatcher();
backApp.setupBackgroundApplication();
} else {
// Start a new app instance for GUI operations.
EntryPointForApplication application = new EntryPointForApplication();
application.enterEventDispatcher();
}
}
}
クラスUIアプリケーション
class GUIApplication extends MainScreen {
public GUIApplication(){
add(new LabelField("Hello World"));
}
}
背景アプリケーション
class BackgroundApplication extends Application {
public BackgroundApplication() {
// TODO Auto-generated constructor stub
}
public void setupBackgroundApplication(){
}
}
これに応じて、blackberry_app_discriptor.xmlを構成しました (編集)悪いリンク
どんな体にも役立ちますか、どこで間違っているのか。
解決
argsの値を記録し、(nullではない場合は)arg [0]をログにして、実際にmain()に渡されているものを確認してください。バックグラウンドモジュールが引数を渡さない(または正しい値を渡さない)コンピレーションプロセスの問題になる可能性があります。
また、エントリーポイントForApplicationインスタンスを静的変数に保存して、参照を維持する(ガベージが収集されていない)ので、既に実行中にホーム画面からアイコンが再度クリックされた場合、複数のインスタンスを開始しないようにしてください。あなたのアプリの。例えば:
class EntryPointForApplication extends UiApplication {
private static EntryPointForApplication theApp;
public EntryPointForApplication() {
GUIApplication scr = new GUIApplication();
pushScreen(scr);
}
public static void main(String[] args) {
if ( args != null && args.length > 0 && args[0].equals("background1") ){
// Keep this instance around for rendering
// Notification dialogs.
BackgroundApplication backApp=new BackgroundApplication();
backApp.setupBackgroundApplication();
backApp.enterEventDispatcher();
} else {
if (theApp == null) {
// Start a new app instance for GUI operations.
theApp = new EntryPointForApplication();
theApp.enterEventDispatcher();
}
}
}
}
所属していません StackOverflow