单击通知后未启动活动

时间:2016-08-03 02:03:30

标签: android android-activity notifications

a尝试了以下代码的8个版本,但单击通知时未启动Home活动。

这是代码(它在服务内部)

NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext());
builder.setSmallIcon(R.mipmap.alert);
builder.setContentTitle("");
builder.setContentText("Running in Background");
builder.setOngoing(true); 

IntenIntenticationIntent = new Intent(getApplicationContext(), Home.class);

PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0,notificationIntent, 0);
notificationManager = (NotificationManager) getApplicationContext().getSystemService(getApplicationContext().NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ID, builder.build());

1 个答案:

答案 0 :(得分:1)

请问下面的代码吗?

Intent notificationIntent = new Intent(this, Home.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setSmallIcon(R.mipmap.alert);
builder.setContentTitle("");
builder.setContentText("Running in Background");
builder.setOngoing(true);
builder.setContentIntent(contentIntent);

notificationManager = (NotificationManager) this.getSystemService(Service.NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ID, builder.build());