如何关闭Android的另一个应用程序? [英] How to close another app in Android?

查看:265
本文介绍了如何关闭Android的另一个应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在开发一个应用程序,而我需要关闭我的code另一个应用程序。没有人知道任何的API调用来关闭一个应用程序?

I have been developing an app, and I need to close another app in my code. Does anyone know any api to call to close an app?

BTW:我的应用程序将是pre安装

BTW: my app will be pre-installed.

感谢

推荐答案

由于的Andr​​oid 2.2 (即前进),你只能关闭后台进程其他应用程序中,你不再能关闭他们的主要活动。

Since Android 2.2 (i.e. going forward), you can only close the background processes of other apps, you are no longer able to close their main activities.

如果您的应用程序的目标是Android的< 2.2,看看 android.permission.RESTART_PACKAGE

If your app is targeting Android <2.2, look atandroid.permission.RESTART_PACKAGE.

如果你想让它在2.2及以上(你应该:-))正常工作,看看 android.permission.KILL_BACKGROUND_PROCESSES ,但是,这只能关闭后台服务和某某可能陷入困境的其他应用程序,而不是做什么好。

If you want it to work properly on 2.2 and above (which you should :-)), look at android.permission.KILL_BACKGROUND_PROCESSES, but again, this only closes background services and such and might "mess up" the other app rather than doing any good.

通过正确的权限,就可以执行以下操作:

With the right permissions, you can then do the following:

private ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
am.restartPackage("com.jimmy.appToBeClosed");

这篇关于如何关闭Android的另一个应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆