[英]Excluding the application from recent app list on invoking finish() on Activity
I have a Service running in the background and at certain periods of time I create notifications with Notification and when the user clicks the notification, it opens an Activity (SurveyForm). 我有一个在后台运行的服务,在某些时间段内,我使用Notification创建通知,并且当用户单击通知时,它会打开一个活动(SurveyForm)。 I want to close that Activity when the user presses a button but leave the background Service running.
我想在用户按下按钮但关闭后台服务运行时关闭该活动。 I am calling the finish() method within the Activity but instead of closing it completely, Application is still present in the recent app list.
我在Activity中调用了finish()方法,但不是完全关闭它,而是在最近的应用程序列表中仍然存在Application。
This is the code that creates the notification. 这是创建通知的代码。
Intent notificationIntent = new Intent(this, SurveyForm.class);
notificationIntent.setAction(Constants.SURVEY_ACTION);
PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Notification notification = new NotificationCompat.Builder(this)
.setContentTitle("Survey")
.setTicker("New Survey")
.setContentText("Please, answer the survey.")
.setSmallIcon(R.drawable.survey_notification_icon)
.setSound(alarmSound)
.setLights(0xff00ff00, 1000, 1000)
.setContentIntent(resultPendingIntent)
.setOngoing(true)
.build();
notification.defaults = Notification.DEFAULT_VIBRATE;
mNotificationManager.notify(Constants.SURVEY_NOTIFICATION_ID, notification);
And the button code is the following: 按钮代码如下:
bSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
//Close the notification
nm.cancel(Constants.SURVEY_NOTIFICATION_ID);
//Close this Activity
finish();
}
});
Update 更新
I have solved the problem by specifying the next property in the manifest file for the corresponding Activity. 我已经通过在清单文件中为相应的Activity指定下一个属性来解决了这个问题。
android:excludeFromRecents="true"
机器人:excludeFromRecents = “真”
I have solved the problem by specifying the excludeFromRecents property in the manifest file for the corresponding Activity. 我已经通过在清单文件中为相应的Activity指定excludeFromRecents属性来解决了这个问题。
android:excludeFromRecents="true"
机器人:excludeFromRecents = “真”
调用finishAndRemoveTask()
而不是finish()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.