简体   繁体   English

如何杀死android中的其他前台活动?

[英]How can I kill other foreground activity in android?

I want to kill OTHER(NOT ITSELF) foreground activity/service. 我想杀死OTHER(NOT ITSELF)个前台活动/服务。 I checked some methods about kill application. 我检查了一些有关终止应用程序的方法。

  1. ActivityManager.restartPackage(String packageName) ActivityManager.restartPackage(String packageName)
    It was deprecated since android 2.2. 自android 2.2起不推荐使用。 So I can't use this method. 所以我不能使用这种方法。

  2. ActivityManager.killBackgroundProcesses(String packageName) ActivityManager.killBackgroundProcesses(String packageName)
    I think it only kills background activities. 我认为这只会杀死后台活动。 But I want to kill foreground services using startForeground(). 但是我想使用startForeground()杀死前台服务。

Is there any method for killing OTHER foreground activity/service? 有什么方法可以杀死其他前台活动/服务?

I reply myself. 我回答自己。

I rooted my device and used NDK to use shell command. 我将设备植根并使用NDK来使用shell命令。

And then using NDK, I killed some applications with this command. 然后使用NDK,使用此命令杀死了一些应用程序。
su -c "am force-stop " su -c“ am force-stop”

也许您可以使用stopForeground(true) ,然后调用stopSelf()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM