如何从最近的应用程序列表中删除应用程

时间:2023-01-21 19:20:09

I guess that Android won't let people to do this, because they think they have perfect handle for the task/applications. However, I really need to do this in my case.

我想Android不会让人们这样做,因为他们认为他们有完美的任务/应用程序处理。但是,在我的情况下,我真的需要这样做。

I have an activity A acting as the entry point of my application. In that activity, it reads the preference and decided which activity to start, say B or C. After that, it finishes itself. So, activity A never appears to the users.

我有一个活动A作为我的申请的入口点。在该活动中,它读取偏好并决定开始哪个活动,比如B或C.之后,它完成了自己。因此,活动A永远不会出现在用户身上。

My application stores things on sdcard, and reads from it constantly. So, when the sdcard is unmounted, I need to display a message to the user that the sdcard is unavailable, instead of opening B or C. I set a check in A to display that message when sdcard is unavilable. When that message is displayed, A will not try to start B or C.

我的应用程序将东西存储在SD卡上,并不断地从中读取。因此,当卸载SD卡时,我需要向用户显示sdcard不可用的消息,而不是打开B或C.我在A中设置检查以在sdcard不可用时显示该消息。显示该消息时,A不会尝试启动B或C.

Things works perfectly if user only enter my application from application launcher. However, I found that user can also enter my application by long pressing home and choose it from the recent application list, if he has opened it recently. When user does that, it skips A and goes directly to B or C. I don't have the check in both of them, so exception is thrown while I am trying to access sdcard, and force close dialog pops up.

如果用户只从应用程序启动器输入我的应用程序,事情就完美无缺。但是,我发现用户也可以通过长按home进入我的应用程序并从最近的应用程序列表中选择它,如果他最近打开它。当用户执行此操作时,它会跳过A并直接转到B或C.我没有检查它们,因此在我尝试访问sdcard时抛出异常,并弹出强制关闭对话框。

I can simply move my check to both B and C to fix this problem. But in the future, the number of activities started from A will increase. If there are 6 of them, I'll need to copy this check to 6 places. Needless to say, this looks very ugly, and is a maintenance nightmare.

我可以简单地将支票移到B和C来解决这个问题。但是在未来,从A开始的活动数量将会增加。如果有6个,我需要将此支票复印到6个地方。毋庸置疑,这看起来非常难看,而且是一场维护噩梦。

So, the best fix should be removing my application from recent application list when the sdcard is uunmounted. However, I can't find how to do this. Even killing the process or use ActivityManager.restartPackage, it still appears in the list. Can anyone tell me how to remove it from the list?

因此,最好的解决方案应该是在卸载SD卡时从最近的应用程序列表中删除我的应用程序。但是,我找不到如何做到这一点。即使查杀进程或使用ActivityManager.restartPackage,它仍会出现在列表中。谁能告诉我如何从列表中删除它?

8 个解决方案

#1


187  

try

尝试

<activity android:name=".MainActivity"
        android:excludeFromRecents="true" ...

in your AndroidManifest.xml's activity declaration.

在AndroidManifest.xml的活动声明中。

#2


16  

Other attributes can help your activity isolate from other activities in the same package.

其他属性可以帮助您的活动与同一包中的其他活动隔离。

<activity 
android:name=".aActivity"
android:excludeFromRecents="true"
android:taskAffinity=""
android:launchMode="singleInstance">

#3


15  

just add android:excludeFromRecents="true" in your activity's tag in the manifest file..its easy

只需在清单文件中的活动标签中添加android:excludeFromRecents =“true”即可

#4


11  

You need to set AndroidManifest.xml:

您需要设置AndroidManifest.xml:

<activity>
  ...
  android:excludeFromRecents="true"
  ...
</activity>

or start this activity from

或从此开始此活动

intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);

and also in AndroidManifest.xml

以及AndroidManifest.xml

<activity>
  ...
  android:label=""
  ...
</activity>

Setting label as empty will let this activity NOT be shown in Recent App list.

将标签设置为空将使此活动不会显示在“最近的应用”列表中。

#5


4  

I would not recommend to do so but I would try the following options:

我不建议这样做,但我会尝试以下选项:

Option 1:

选项1:

On B and C add:

在B和C上添加:

protected void onPause() {
  finish();
}

Option 2:

选项2:

Add to B and C the following in the AndroidManifest:

在AndroidManifest中添加以下B和C:

android:noHistory= "true"

#6


4  

Removing your application from the recent apps list is probably not possible, and definitely not the best solution. That will just confuse the user who expects all apps to behave similarly.

从最近的应用程序列表中删除您的应用程序可能是不可能的,并且绝对不是最佳解决方案。这只会让期望所有应用程序行为相似的用户感到困惑。

Regardless, I don't think it will solve your problem. If the user hits home while on Activity B, then selects your app from the home page, it will start Activiy B again.

无论如何,我认为它不会解决你的问题。如果用户在活动B上回家,然后从主页选择您的应用程序,它将再次启动Activiy B.

There are a number of ways to solve the real problem. One easy one might be to create a base Activity that performs the SD card check, and have all of your activities extend from it. That way the check is only in one place.

有许多方法可以解决实际问题。一个简单的方法可能是创建一个执行SD卡检查的基本活动,并让您的所有活动都从中扩展。这样检查只在一个地方。

#7


2  

OK, I know for a fact that it can be done in 2.3.4. The app Toddler Lock when opened clears the recent app list so that when you "Lock" your phone if you long press home key the list is blank. Unfortunately I have not found how to do it. So for anyone who is looking and reading postf that say it is not possible don't give up. I sure heck am not.

好的,我知道它可以在2.3.4中完成。打开应用程序Toddler Lock会清除最近的应用程序列表,这样当您长按主页键“锁定”手机时,列表为空白。不幸的是我还没有找到怎么做。所以对于那些正在寻找和阅读postf的人来说,说不可能不要放弃。我确定不是。

#8


0  

if you wanna exit Application on Button click use this code :

如果您想退出按钮上的应用程序,请单击以下代码:

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);

To kill the complete app and remove it from Runningapp list kill the app through its pid(its nasty)... use this lines before above code.

要杀死完整的应用程序并从Runningapp列表中删除它通过其pid杀死应用程序(它讨厌)...在上面的代码之前使用这一行。

int pid = android.os.Process.myPid();
android.os.Process.killProcess(pid);

#1


187  

try

尝试

<activity android:name=".MainActivity"
        android:excludeFromRecents="true" ...

in your AndroidManifest.xml's activity declaration.

在AndroidManifest.xml的活动声明中。

#2


16  

Other attributes can help your activity isolate from other activities in the same package.

其他属性可以帮助您的活动与同一包中的其他活动隔离。

<activity 
android:name=".aActivity"
android:excludeFromRecents="true"
android:taskAffinity=""
android:launchMode="singleInstance">

#3


15  

just add android:excludeFromRecents="true" in your activity's tag in the manifest file..its easy

只需在清单文件中的活动标签中添加android:excludeFromRecents =“true”即可

#4


11  

You need to set AndroidManifest.xml:

您需要设置AndroidManifest.xml:

<activity>
  ...
  android:excludeFromRecents="true"
  ...
</activity>

or start this activity from

或从此开始此活动

intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);

and also in AndroidManifest.xml

以及AndroidManifest.xml

<activity>
  ...
  android:label=""
  ...
</activity>

Setting label as empty will let this activity NOT be shown in Recent App list.

将标签设置为空将使此活动不会显示在“最近的应用”列表中。

#5


4  

I would not recommend to do so but I would try the following options:

我不建议这样做,但我会尝试以下选项:

Option 1:

选项1:

On B and C add:

在B和C上添加:

protected void onPause() {
  finish();
}

Option 2:

选项2:

Add to B and C the following in the AndroidManifest:

在AndroidManifest中添加以下B和C:

android:noHistory= "true"

#6


4  

Removing your application from the recent apps list is probably not possible, and definitely not the best solution. That will just confuse the user who expects all apps to behave similarly.

从最近的应用程序列表中删除您的应用程序可能是不可能的,并且绝对不是最佳解决方案。这只会让期望所有应用程序行为相似的用户感到困惑。

Regardless, I don't think it will solve your problem. If the user hits home while on Activity B, then selects your app from the home page, it will start Activiy B again.

无论如何,我认为它不会解决你的问题。如果用户在活动B上回家,然后从主页选择您的应用程序,它将再次启动Activiy B.

There are a number of ways to solve the real problem. One easy one might be to create a base Activity that performs the SD card check, and have all of your activities extend from it. That way the check is only in one place.

有许多方法可以解决实际问题。一个简单的方法可能是创建一个执行SD卡检查的基本活动,并让您的所有活动都从中扩展。这样检查只在一个地方。

#7


2  

OK, I know for a fact that it can be done in 2.3.4. The app Toddler Lock when opened clears the recent app list so that when you "Lock" your phone if you long press home key the list is blank. Unfortunately I have not found how to do it. So for anyone who is looking and reading postf that say it is not possible don't give up. I sure heck am not.

好的,我知道它可以在2.3.4中完成。打开应用程序Toddler Lock会清除最近的应用程序列表,这样当您长按主页键“锁定”手机时,列表为空白。不幸的是我还没有找到怎么做。所以对于那些正在寻找和阅读postf的人来说,说不可能不要放弃。我确定不是。

#8


0  

if you wanna exit Application on Button click use this code :

如果您想退出按钮上的应用程序,请单击以下代码:

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);

To kill the complete app and remove it from Runningapp list kill the app through its pid(its nasty)... use this lines before above code.

要杀死完整的应用程序并从Runningapp列表中删除它通过其pid杀死应用程序(它讨厌)...在上面的代码之前使用这一行。

int pid = android.os.Process.myPid();
android.os.Process.killProcess(pid);