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; }

iOS: Keep an app running like a service

Basically, there is no such thing as a service type app or functionality in iOS. Even the “background” apps (UIBackgroundMode) cannot run entirely free and without restrictions like a service or daemon etc. on other OSs can. Here’s the situation regarding background execution and notifications and timers etc. 1) An app cannot execute in the … Read more

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