后台的Android通知会继续以前的意图

时间:2016-05-10 10:57:49

标签: android android-intent push-notification notifications android-notifications

sendNotification('Hello', 0, 1);

private void sendNotification(String message, int id, int notification_num) {

    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    Intent intent = new Intent(this, Main.class);
    intent.setData(new Uri.Builder().scheme("data").build());
    intent.putExtra("id", id);
    intent.putExtra("noti_number", notification_num);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(Main.class);
    stackBuilder.addNextIntent(intent);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, id, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setContentTitle("App Title")
            .setContentText(message)
            .setSmallIcon(R.drawable.notif)
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);
    notificationBuilder.setNumber(notification_num);
    nm.notify(id, notificationBuilder.build());

}

当打开应用程序时,intent.putExtra工作正常,但是当我关闭应用程序(kill proccess)时,通知即将到来,但不会超出新的额外意图。

问题还在于多个通知,当应用关闭时,没有像我希望的那样分组。 notificationBuilder.setNumber在后台始终为0。

需要帮助如何在后台运行应用程序或如何继续以前的意图。

1 个答案:

答案 0 :(得分:0)

我使用GcmIntentService& GcmBroadcastReceiver,有关详情,请点击on this link