2つのアプリケーションを作成しました。
1つのアプリケーションはメッセージ受信者(app1)であり、別のアプリケーション(app2)はメッセージに基づいて他のタスクを実行するためのものです。
最初のアプリケーション(app1)はメッセージを受信し、通知を作成して上部に表示されます。ユーザーが通知をクリックすると、別のアプリケーション(app2)が呼び出され、メッセージに基づいて他のタスクが実行されます。
アプリケーション(app2)が実行されていない場合は、起動する必要があります。すでに実行されている場合は、インスタンスが表示され、実行するタスクが表示されます。
私は次のコードを使用しています:
protected void displayNotification() {
Notification notification = new Notification(icon, tickerText, when);
Bundle xtra = new Bundle();
Intent ntent = new Intent(Intent.ACTION_SEND);
ntent.setClassName("com.example.mytestapp",
"com.example.mytestapp.MainActivity");
xtra.putString("id", "8610B0DD");
xtra.putParcelable("message", msg);
ntent.putExtras(xtra);
ntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ntent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
ntent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(context, contentTitle, contentText,
pendingIntent);
final int button_Click = 1;
nm.notify(button_Click, notification);
}
これは正常に機能しますが、別のアプリケーション(app2)の複数のインスタンスを作成します。
この複数のコピーの作成を防ぐ方法はありますか?