この問題については、多くのStack Overflow投稿がありますが、Notification.Builderクラスを使用する代わりに、現在は非推奨のNotificationメソッドを使用しています。ステータスバー通知からアクティビティが開始されない
ステータスバーの通知を正常に作成していますが、クリックしても何も起こりません。 LogCatでの警告は、最大を示しています。ここでは
Window already focused, ignoring focus gain of: [email protected]
は、私は私の通知を構築するために使用しているコードです:
public class LunchNotificationBuilder {
private Notification notification;
public LunchNotificationBuilder(Lunch lunch, Context context) {
Builder builder = new Builder(context);
Calendar reminderTime = (Calendar)lunch.getReminderTime().clone();
builder.setWhen(reminderTime.getTimeInMillis());
builder.setTicker("Reminder for " + lunch.getTitle());
builder.setContentTitle("LunchBunch Notification");
builder.setContentText("Upcoming lunch at " + lunch.getTitle());
builder.setSmallIcon(R.drawable.ic_launcher);
Intent intent = new Intent(context, InviteDetails.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
builder.setContentIntent(PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT));
this.notification = builder.getNotification();
}
public Notification getNotification() {
return this.notification;
}
}
ランチクラスは心配しないでください、私が作成したばかりのデータ構造でありますそれ。
渡されるコンテキストは、Application.getApplicationContext()です。
ドキュメントで示唆しているようにIntent.FLAG_ACTIVITY_NEW_TASKフラグを設定しています.PendingIntentにはPendingIntent.FLAG_ONE_SHOTフラグが設定されています。
別の注:コード内のstartActivityを明示的に呼び出すと、私が起動しようとしているアクティビティ(InviteDetails)はうまく動作します。このPendingIntentビジネスに関する何かが機能していません。
getActivityで別のrequestCodeを渡すようにしてください。 [これはA2.3エミュレータで動作します](http://pastebin.com/Qa983XfB)しかし、あなたが望むものではないかもしれません。 – Deucalion