Replace getRunningServices(int) for a newer method

252 views Asked by At

I have a function that is using getRunningServices(int) and is working fine, but it is deprecated. I have searched in the forum similar questions and I have found one question with exactly the same function I am using, but the answers were just avoiding the problem, not solving it.

This is the similar post: similar post

This is the function I would want to replace with a non-deprecated method:

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

How could I replace that deprecated method? Thanks for the help.

0

There are 0 answers