如何从另一个应用程序启动应用 [英] How to launch an app from another app
本文介绍了如何从另一个应用程序启动应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序,我必须启动其他应用程序,只有当它尚未推出。
in my app i have to launch another app, only if it is not yet launched.
要启动一个应用程序我做的是:
To launch an app what i do is:
PackageManager pm = getPackageManager();
Intent intent = pm.getLaunchIntentForPackage("package.of.app.to.launch");
startActivity(intent);
我的问题是,如果应用程序已经启动,它会带来应用到前台。我怎样才能启动的应用程序只有在处于非活动,并推出应用present?谢谢!
My problem is that if app is already launched, it will bring the app to the front. How can i launch app only if is not present in active and launched apps? thanks!
推荐答案
您可以使用的 ActivityManager 获取当前运行的应用程序,并获得作为设备执行任务的最近的:
You can use ActivityManager to get Currently running Applications and to get recent task executed on Device as:
ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> recentTasks = activityManager.getRunningTasks(Integer.MAX_VALUE);
for (int i = 0; i < recentTasks.size(); i++)
{
// Here you can put your logic for executing new task
}
这篇关于如何从另一个应用程序启动应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文