I was trying to check to see what application or activity is currently in the foreground/being used by a user from a service i created by doing:
ActivityManager am = (ActivityManager) getApplicationContext().getSystemService(
Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> processList = am.getRunningAppProcesses();
String cProcess = processList.get(0).processName;
but this sometimes shows services like com.android.systemui or com.android.buetooth even when a different activity is in the fore ground..
i guess this is checking services instead of activities.. is there a better more reliable way to see what application is currently in the foreground?
I think that
activityManager.getRunningTasks()is more what you’re looking for, although be aware the Android developers warn against using theActivityManagerfor any core feature for your application.