diff --git a/NotificationScheduler/app/src/main/java/com/android/example/notificationscheduler/MainActivity.java b/NotificationScheduler/app/src/main/java/com/android/example/notificationscheduler/MainActivity.java index b408c28a..3e888c21 100644 --- a/NotificationScheduler/app/src/main/java/com/android/example/notificationscheduler/MainActivity.java +++ b/NotificationScheduler/app/src/main/java/com/android/example/notificationscheduler/MainActivity.java @@ -51,8 +51,6 @@ protected void onCreate(Bundle savedInstanceState) { final TextView seekBarProgress = findViewById(R.id.seekBarProgress); - mScheduler = (JobScheduler) getSystemService(JOB_SCHEDULER_SERVICE); - // Updates the TextView with the value from the seekbar. mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override @@ -119,6 +117,9 @@ public void scheduleJob(View view) { if (constraintSet) { JobInfo myJobInfo = builder.build(); + if (mScheduler == null) { + mScheduler = (JobScheduler) getSystemService(JOB_SCHEDULER_SERVICE); + } mScheduler.schedule(myJobInfo); Toast.makeText(this, R.string.job_scheduled, Toast.LENGTH_SHORT) .show();