简体   繁体   English

在Activity上调用finish()时从最近的应用程序列表中排除该应用程序

[英]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.

相关问题 如果应用程序之前未显示最近的应用列表,则应用程序不应在完成活动后显示在最近的应用列表中 - Application should not display in recent app list after finish the activity if app was not displaying recent app list previously 如何在完成时从最近的应用列表中删除活动? - How to remove activity from recent apps list on finish? 活动会从最近的应用列表中删除该应用 - An Activity removes the app from recent apps list 从最近的应用列表中删除一个应用 - Removing an application from the recent app list 关闭活动时从“最近使用的应用程序”中删除应用程序 - Remove application from Recent app while closing the activity 从NFC启动的活动/应用程序永远不会出现在最近的应用程序列表中 - Activity/Application Launched From NFC Never Appears in Recent Apps List 防止活动从android中的最新应用列表运行 - Prevent activity run from recent app list in android 当应用程序从 android 的最近列表中删除时,会调用哪个活动? - Which activity is called when app removed from recent list in android? 如何在没有完成活动的情况下从最近的列表返回上一个应用 - How to back to last app from recent list without finishing activity Android-从操作系统的应用程序“最近使用的应用程序”列表中启动的活动 - Android - Activity launched from the OS's app recent apps list
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM