When i start application from another one through
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory("android.intent.category.LAUNCHER");
intent.setComponent(new ComponentName("com.app.app", "com.app.app.Main"));
startActivity(intent);
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> runningProcInfo = activityManager.getRunningAppProcesses();
Log.e("TAG", "runningProcInfo.get(0).processName "+runningProcInfo.get(0).processName);
And I am getting Home application package
What is wrong in my code?
There is nothing wrong with the code.
From the
ActivityManager.getRunningAppProcesses()documentation: “Returns a list of RunningAppProcessInfo records, or null if there are no running processes (it will not return an empty list). This list ordering is not specified.“So,
runningProcInfo.get(0)could be any process that’s currently running, not necessarily the foreground one.