我创建了一个通知,通过点击它我创建了一个活动。但是当我关闭活动时,它在视觉上是关闭的,但仍然挂在打开的应用程序列表中。如何以这种方式关闭活动?
// I create a notification
Intent intent = new Intent(this, NotificationActivity.class);
intent.putExtra("text", text);
PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0);
Notification n = new Notification.Builder(this)
.setContentTitle(getString(R.string.app_name))
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pIntent)
.setStyle(new Notification.BigTextStyle().bigText(message))
.setAutoCancel(true).build();
notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, n);
// I close activity, which is shown by clicking on the notification
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.buttonClose:
finish();
break;
}
}
}
即活动从屏幕上消失,但如果您在设备上打开打开的应用程序,则可以在那里看到它。