Android 10 on killed of app(i.e. swiped out app from recent apps) the job scheduler to detect internet is not working

138 Views Asked by At

I have created a job scheduler which is started by a job service to detect when the device connects to network. But this scheduler doesn't work on android 10 devices.

`

try {
        ComponentName componentName = 
                        new ComponentName(SplashScreenActivity.this,JobSchedulerService.class);

        JobInfo jobInfo = new JobInfo.Builder(13, componentName)
                          .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
                          .setPersisted(true)
                           .build();

       JobScheduler jobScheduler = 
                    (JobScheduler) getSystemService(JOB_SCHEDULER_SERVICE);
                        int resultCode = jobScheduler.schedule(jobInfo);
                        if (resultCode == JobScheduler.RESULT_SUCCESS) {
                            Log.d("Job", "Job scheduled!");
                        } else {
                            Log.d("Job", "Job not scheduled");
                        }
                    } catch (Exception ex) {
                        ex.printStackTrace();
                        Logger.e(getApplicationContext(), "SplashScreenActivity", "Job-", ex);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

`

0

There are 0 best solutions below