关闭后开始相同的活动

时间:2015-09-01 07:58:47

标签: java android

在我的应用程序中,我从通知栏以及主屏幕启动活动。问题是如果我的活动已经打开,然后从通知栏再次打开它,然后按下后退按钮,活动再次打开。我想在通知栏中启动之前完成活动。以下是从通知栏启动活动的代码。

private void createNotification(){

String ns = Context.NOTIFICATION_SERVICE;
NotificationManager notificationManager = (NotificationManager) getSystemService(ns);

Notification notification = new Notification(R.drawable.ic_launcher, null, System.currentTimeMillis());
RemoteViews notificationView = new RemoteViews(getPackageName(), R.layout.notification);

//the intent that is started when the notification is clicked (works)

Intent notificationIntent = new Intent(this, DBRoulette.class);
PendingIntent pendingNotificationIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

notification.contentView = notificationView;
notification.contentIntent = pendingNotificationIntent;
notification.flags |= Notification.FLAG_NO_CLEAR;

//this is the intent that is supposed to be called when the button is clicked
Intent switchIntent = new Intent(this, Service1.class);
PendingIntent pendingSwitchIntent = PendingIntent.getService(this, 0, switchIntent, 0);

notificationView.setOnClickPendingIntent(R.id.start, pendingSwitchIntent);

notificationManager.notify(1, notification);

//这是单击按钮时应该调用的意图     Intent switchIntent1 = new Intent(this,Service2.class);     PendingIntent pendingSwitchIntent1 = PendingIntent.getService(this,0,switchIntent1,0);

notificationView.setOnClickPendingIntent(R.id.stop, pendingSwitchIntent1);

notificationManager.notify(1, notification);

}

0 个答案:

没有答案