0

アクティビティが起動した通知をクリックして、通知を作成するブロードキャストレシーバーを作成しました。そのアクティビティは起動していますが、表示できませんでした。次のコードを使用しています。

private NotificationManager notificationManager;
    @Override
public void onReceive(Context context, Intent intent) {
    if (notificationManager == null) {
        notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
    }
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setTicker("Its Ticker")
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle("Notification Title")
            .setContentText("Its Content")
            .setAutoCancel(true)
            .setContentIntent(PendingIntent.getActivity(context,0,new Intent(context, NotificationDialog.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK),0));
    notificationManager.notify("interstitial_tag", 0, builder.getNotification());

}

注:NotificationDialog.javaこれは私のアクティビティです。このアクティビティは、デバッグしたときに実行されていますが、表示されていません。何時間も試してみましたが、答えが見つかりませんでした。提案をいただければ幸いです。

4

1 に答える 1

0

FLAG_ACTIVITY_CLEAR_TASKの代わりにFLAG_ACTIVITY_CLEAR_TOPを使用してください

private NotificationManager notificationManager;
    @Override
public void onReceive(Context context, Intent intent) {
    if (notificationManager == null) {
        notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
    }
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setTicker("Its Ticker")
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle("Notification Title")
            .setContentText("Its Content")
            .setAutoCancel(true)
            .setContentIntent(PendingIntent.getActivity(context,0,new Intent(context, NotificationDialog.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP),0));
    notificationManager.notify("interstitial_tag", 0, builder.getNotification());

}
于 2012-07-12T10:25:52.813 に答える