我知道如何将任何应用程序放在前台,但我现在会将任何应用程序放在后台。即,我想要的每个应用程序。我在谷歌上搜索了很多,但我没有找到解决方案。你知道怎么做吗?我试图显示家,但它不起作用:
Intent i = new Intent(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
startActivity(i);
非常感谢您提前。
这是我的所有代码(它是一个测试代码),我启动了地图应用程序,然后我想要把它放在背景中:
List<ResolveInfo> pkgAppsList = retreivedAllApplicationsInstalled();
ActivityManager actMngr = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
List<RunningAppProcessInfo> runningAppProcesses = actMngr.getRunningAppProcesses();
for (RunningAppProcessInfo pi : runningAppProcesses) {
String[] testPklist = pi.pkgList;
if(pi.importance == RunningAppProcessInfo.IMPORTANCE_BACKGROUND){
for(String tp : testPklist){
if(tp.equals("com.google.android.apps.maps")){
//launch map application
Intent i = new Intent(Intent.ACTION_MAIN);
PackageManager manager = getPackageManager();
i = manager.getLaunchIntentForPackage("com.google.android.apps.maps");
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
}
}
}
}
//try to put back all applications on displaying home
Intent back = new Intent(Intent.ACTION_MAIN);
back.addCategory(Intent.CATEGORY_HOME);
startActivity(back);