Periodic Job not scheduled after reboot
See original GitHub issueHello, 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:
- Created 5 years ago
- Comments:5
Top GitHub Comments
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
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