How to check JobService is running or not in android?

后端 未结 1 581
自闭症患者
自闭症患者 2020-12-25 09:03

I am using JobService in my project. It\'s working good. But sometimes service stopped. It is not restart again. So that I am trying to strat the JobService if not running.

1条回答
  •  一生所求
    2020-12-25 09:36

    I got the solution.

    public static boolean isJobServiceOn( Context context ) {
        JobScheduler scheduler = (JobScheduler) context.getSystemService( Context.JOB_SCHEDULER_SERVICE ) ;
    
        boolean hasBeenScheduled = false ;
    
        for ( JobInfo jobInfo : scheduler.getAllPendingJobs() ) {
            if ( jobInfo.getId() == JOB_ID ) {
                hasBeenScheduled = true ;
                break ;
            }
        }
    
        return hasBeenScheduled ;
    }
    

    Using of this method we can check jobService is running or not.

    0 讨论(0)
提交回复
热议问题