Android - 当用户点击条形图中的通知时,如何不启动活动

时间:2013-12-16 12:12:54

标签: android android-intent

当用户在显示活动A时点击状态栏中的通知时,我不想启动活动,但是当A被销毁或不可见时,当用户点击通知时,活动已经正常启动。

我该怎么办?谢谢!

更新,这是我显示通知的代码:

Intent notificationIntent = new Intent(context, MainActivity.class);
    notificationIntent.putExtra(GCMReceiver.EXTRA_NOTIFICATION_MESSAGE,
            notiMessage);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
            | Intent.FLAG_ACTIVITY_NEW_TASK);

    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
            notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
            this.context);      
    mBuilder.setContentText(message);

    mBuilder.setContentTitle(title);
    mBuilder.setAutoCancel(true).setSmallIcon(R.drawable.ic_notification)
            .setContentIntent(pendingIntent);       
    mNotificationManager.notify(KEY_PUSH_NOTIFICATION, mBuilder.build());

1 个答案:

答案 0 :(得分:0)

当用户点击通知时,您可以初始化pendingIntent,如下所示:

PendingIntent contentIntent = 
                PendingIntent.getActivity(context, 0, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT); 

        builder.setContentIntent(contentIntent);