1

ステータスバー通知から startActivityForResult() を使用することは可能ですか?

あるイベントで startActivityForResult() を使用してアクティビティ B を開始するアクティビティ A があるとします。バックグラウンドでイベントが発生すると、通知が表示されるようになりました。通知を選択すると、結果のアクティビティ B を開始するにはどうすればよいですか?

アクティビティ A にはバックグラウンドで実行されるサービスが必要であることは理解していますが、その場合でも同じ質問が当てはまると思います。

通知のコードは次のとおりです。これはアクティビティ A にあります。

    Notification notification = new Notification(R.drawable.ic_launcher, "New Notification", System.currentTimeMillis());

    notification.flags = Notification.FLAG_AUTO_CANCEL;
    CharSequence contentTitle = "My Notification Title";
    CharSequence contentText = "My Notification Text";
    Intent notificationIntent = new Intent(this, ActivityB.class);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    notification.setLatestEventInfo(getApplicationContext(), contentTitle, contentText, contentIntent);

    nm.notify(1, notification);  //1 = id
4

2 に答える 2

3

I think that you should just start the activity A from the activity B when the activity B is opened by opening the notification and then closed. You can pass the return value in the intent that you use to start the activity A from the activity B.

于 2012-04-08T21:47:03.117 に答える
1

startActivityForResultを使用しないでください。同じ機能をさまざまな方法で実現できます。結果を通知とともに追加で渡します。この結果をアクティビティBのonResumeで取得します。

于 2012-04-08T08:57:50.993 に答える