From b263e5e0a78479bb595547ffa04329a0283693df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Horv=C3=A1th?= Date: Tue, 9 Apr 2019 18:31:30 +0200 Subject: [PATCH] NotificationScheduler/app/src/main/java/com/android/example/notificationscheduler/MainActivity.java: Fix scheduler crash --- .../android/example/notificationscheduler/MainActivity.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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();