question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Periodic Job not scheduled after reboot

See original GitHub issue

Hello, I´m writing an app that is periodically connecting to a server and checking for new messages. If the app gets opened is shows the new notifications. And if the app ist closed the app shows notifications in the statusbar.

I used the evernote Job Scheduler to do this check periodically every 15 minutes and it is working fine till i delete the app from “last apps used” or (and thats the problem) if i restart the device.

I am testing with two devices, (API 23 and 27)

Is it my fault? Or maybe isn´t it possible to reschedule a periodic job after reboot without starting the app?

Here are my classes: (This is my first issue an github -> if i made a mistake, please tell me)

public class MainActivity extends AppCompatActivity implements ListView.OnItemClickListener { ... protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); JobManager.create(this).addJobCreator(new TestJobCreator()); SyncJob.scheduleJob(); }

public class TestJobCreator implements com.evernote.android.job.JobCreator { @Nullable @Override public Job create(@NonNull String tag) { switch (tag) { case SyncJob.TAG : return new SyncJob(); default : return null; } } }

`public class SyncJob extends Job {

private final static String CHANNEL_ID = "TestID";
public static final String TAG = "job_sync_tag";
private final static int GROUP_ID = 231323;

AppStorageOffline appStorageOffline;
AppStorageOnline appStorageOnline;
AppSettings appSettings;

@NonNull
@Override
protected Result onRunJob(@NonNull Params params) {
    Log.d("SyncJob", "onRunJob");
    checkNotifications();
    return Result.RESCHEDULE;
}

public static void scheduleJob() {
    Log.d("SyncJob", "scheduleJob");
    new JobRequest.Builder(SyncJob.TAG)
            .setPeriodic(TimeUnit.MINUTES.toMillis(15), TimeUnit.MINUTES.toMillis(15))
            .setRequiredNetworkType((JobRequest.NetworkType.CONNECTED))
            .setUpdateCurrent(true)
            .build()
            .schedule();
}

private void checkNotifications() {
   ....
}

}`

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
DarkF1eldcommented, May 24, 2018

ok, you are right, i fixed it using an “AddJobCreatorReceiver”-Class and added this class to AndroidManifest.xml like this: </activity> <receiver android:name=".AddReceiver" android:exported="false"> <intent-filter> <action android:name="com.evernote.android.job.ADD_JOB_CREATOR"/> </intent-filter> </receiver> </application>

My Receiver-Class: public final class AddReceiver extends JobCreator.AddJobCreatorReceiver { @Override protected void addJobCreator(@NonNull Context context, @NonNull JobManager manager) { manager.addJobCreator(new TestJobCreator()); } }

Problem is solved, Thanks for your help

0reactions
vRallevcommented, May 23, 2018

Everything works as expected. Your problem is that after a reboot or closing your app you don’t launch the MainActivity and thus don’t add the job creator. When the library tries to start you job, it doesn’t know how to map your tag to your job, because your creator doesn’t exist. It’s to add the job creator in the application class, like described here: https://github.com/evernote/android-job#usage

2018-05-23 09:08:30.830 1675-2653/system_process I/ActivityManager: Start proc 3196:appdevelopment.darkfield.tinysampleapp/u0a86 for broadcast appdevelopment.darkfield.tinysampleapp/com.evernote.android.job.JobBootReceiver
2018-05-23 09:08:30.839 3196-3196/appdevelopment.darkfield.tinysampleapp W/zygote: Unexpected CPU variant for X86 using defaults: x86
2018-05-23 09:22:54.096 3196-4480/appdevelopment.darkfield.tinysampleapp D/PlatformJobService: Run job, request{id=2, tag=job_sync_tag, transient=false}, waited 00:14:57, interval 00:15:00, flex 00:15:00
2018-05-23 09:22:54.096 3196-4480/appdevelopment.darkfield.tinysampleapp W/JobCreatorHolder: no JobCreator added
2018-05-23 09:22:54.096 3196-4480/appdevelopment.darkfield.tinysampleapp W/JobExecutor: JobCreator returned null for tag job_sync_tag
2018-05-23 09:38:19.514 3196-5260/appdevelopment.darkfield.tinysampleapp D/PlatformJobService: Run job, request{id=2, tag=job_sync_tag, transient=false}, waited 00:30:22, interval 00:15:00, flex 00:15:00
2018-05-23 09:38:19.514 3196-5260/appdevelopment.darkfield.tinysampleapp W/JobCreatorHolder: no JobCreator added
2018-05-23 09:38:19.514 3196-5260/appdevelopment.darkfield.tinysampleapp W/JobExecutor: JobCreator returned null for tag job_sync_tag
2018-05-23 09:52:54.086 3196-6031/appdevelopment.darkfield.tinysampleapp D/PlatformJobService: Run job, request{id=2, tag=job_sync_tag, transient=false}, waited 00:44:57, interval 00:15:00, flex 00:15:00
2018-05-23 09:52:54.086 3196-6031/appdevelopment.darkfield.tinysampleapp W/JobCreatorHolder: no JobCreator added
2018-05-23 09:52:54.086 3196-6031/appdevelopment.darkfield.tinysampleapp W/JobExecutor: JobCreator returned null for tag job_sync_tag
2018-05-23 10:09:09.407 3196-6927/appdevelopment.darkfield.tinysampleapp D/PlatformJobService: Run job, request{id=2, tag=job_sync_tag, transient=false}, waited 01:01:12, interval 00:15:00, flex 00:15:00
2018-05-23 10:09:09.407 3196-6927/appdevelopment.darkfield.tinysampleapp W/JobCreatorHolder: no JobCreator added
2018-05-23 10:09:09.407 3196-6927/appdevelopment.darkfield.tinysampleapp W/JobExecutor: JobCreator returned null for tag job_sync_tag
Read more comments on GitHub >

github_iconTop Results From Across the Web

Scheduled task may not run upon reboot if machine was off at ...
This article helps solve an issue where a scheduled task may not run upon reboot if the machine is off at the time...
Read more >
Android Periodic job scheduler not running after device reboot
I have schedule a periodic Job which is as below : ComponentName serviceComponent = new ComponentName(context, MyJobService.class); JobInfo.
Read more >
SQL Server Jobs not being scheduled after restart
I ran this script which brings SQL Agent online, but ALL the jobs "Next Run" is set to "Not scheduled". EXEC sp_configure 'allow...
Read more >
Restarting event related periodic background jobs
Dear All, I have scheduled a periodic background job with 'after event' option. ... name has not yet ended but the previous job...
Read more >
Running Scheduled Jobs in Spring Boot - Reflectoring
Scheduled jobs are a piece of business logic that should run on a timer. ... We have not added any dependencies to Maven...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found