我的应用程序中有通知在使用AlarmManager的特定时间段后被触发。通知有两个按钮,一个执行向数据库的写入,另一个是忽略按钮,它只是删除通知。但问题是,它打开了应用程序的活动,这是不应该发生的,为什么?下面是通知的设置方式
public static void sendNotification(Context context) {
NotificationManager mNotifyManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
mBuilder.setContentTitle("My LeApp")
.setContentText("New event!")
.setContentIntent(getPendingIntent(context, 0, ActivityStage2.class))
.setSmallIcon(R.drawable.notif_icon)
.addAction(R.drawable.notif_take, "Take", getPendingIntent(context, 1, Take.class))
.addAction(R.drawable.notif_ignore, "Ignore", getPendingIntent(context, 2, Ignore.class))
.setAutoCancel(true);
mNotifyManager.notify(0, mBuilder.build());下面是Ignore活动
public class Ignore extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Context.NOTIFICATION_SERVICE != null) {
NotificationManager nMgr = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
nMgr.cancel(0);
}
}}
发布于 2014-09-25 22:36:45
单击取消按钮后,您将打开一个活动页面。
没有使用,但我可以给一个建议,以避免这种情况..
使用一个BroadcasrReceiver而不是Activity,并取消onReceive()内部的通知。
https://stackoverflow.com/questions/26040817
复制相似问题