Foreground Vs Active window

The active window (the result of GetActiveWindow()) is the window attached to the calling thread that gets input. The foreground window (the result of of GetForegroundWindow()) is the window that’s currently getting input regardless of its relationship to the calling thread. The active window is essentially localized to your application; the foreground window is global … Read more

How do I bring an unmanaged application window to front, and make it the active window for (simulated) user input

If you don’t have a handle to the window, use this before : [DllImport(“user32.dll”, SetLastError = true)] static extern IntPtr FindWindow(string lpClassName, string lpWindowName); Now assuming you have a handle to the application window : [DllImport(“user32.dll”, SetLastError = true)] static extern bool SetForegroundWindow(IntPtr hWnd); This will make the taskbar flash if another window has keyboard … Read more

How to determine if an Android Service is running in the foreground?

public static boolean isServiceRunningInForeground(Context context, Class<?> serviceClass) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (serviceClass.getName().equals(service.service.getClassName())) { if (service.foreground) { return true; } } } return false; }

How to startForeground() without showing notification?

As a security feature of the Android platform, you cannot, under any circumstance, have a foregrounded service without also having a notification. This is because a foregrounded service consumes a heavier amount of resources and is subject to different scheduling constraints (i.e., it doesn’t get killed as quickly) than background services, and the user needs … Read more

Context.startForegroundService() did not then call Service.startForeground()

From Google’s docs on Android 8.0 behavior changes: The system allows apps to call Context.startForegroundService() even while the app is in the background. However, the app must call that service’s startForeground() method within five seconds after the service is created. Solution: Call startForeground() in onCreate() for the Service which you use Context.startForegroundService() See also: Background … Read more