我正在发送通知,当用户按下通知时,它将返回应用而不是开始新活动。因为我在背景上有倒数计时器,我不想开始新的活动。这是我的通知代码:
//somecode
PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 1, Mainactivity.class, 0);
Notification.Builder builder = new Notification.Builder(MainActivity.this);
builder.setAutoCancel(false);
builder.setTicker("this is ticker text");
builder.setContentTitle("WhatsApp Notification");
builder.setContentText("You have a new message");
builder.setSmallIcon(R.drawable.ic_launcher);
builder.setContentIntent(pendingIntent);
builder.setOngoing(true);
builder.setSubText("This is subtext..."); //API level 16
builder.setNumber(100);
builder.build();
myNotication = builder.getNotification();
manager.notify(11, myNotication)
通知正常,但是当我按下通知时,它会启动新活动,而不是我当前的应用页面。任何帮助,将不胜感激。谢谢!
答案 0 :(得分:0)
添加
android:launchMode="singleTop"
到你应用的Manifest。
如果调用者任务中堆栈顶部已存在具有相同类型的Activity
实例,则此launchmode
表示未创建新的Activity
。相反,堆栈上的Activity
将收到Intent