简体   繁体   中英

Android - How doesn't start activity when user clicks a notification in bar

I don't want to start activity when user clicks on notification in status bar when activity A is showing, but when A has been destroyed or invisiable, activity has been start normally when user click a notification.

How can I do? Thanks!

Update, this is my code to show Notification:

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());

You can init your pendingIntent like below for not opening class when user click on notification:

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

        builder.setContentIntent(contentIntent);  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM