Android how to check if the intent service is stil

2019-01-12 21:29发布

I need to know if all intentservices in the queue are "consumed" or the other way is to find out if it is still doing something so that I don't continue until all services have stopped running. Any ideas?

1条回答
爷的心禁止访问
2楼-- · 2019-01-12 21:55

Try this may be useful for u

private boolean isMyServiceRunning() {
    ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if ("com.example.MyService".equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}
查看更多
登录 后发表回答