I want to perform a method with a debacle and for the implementation of this idea, I chose the library from Evernote "Android-Job". The problem is that I seem to have done everything as stated in the documentation, but when I launch the application, nothing happens. My code ...
This is the class that is responsible for all the functionality of this library:
public class PollingDataJob extends Job { static final String TAG = "polling_data_job_tag"; @NonNull @Override protected Result onRunJob(Params params) { Log.e(TAG, "onRunJob"); String query = QueryPreferences.getStoredQuery(getContext()); String lastResultId = QueryPreferences.getLastResultId(getContext()); List<GalleryItem> items; if (query == null) { items = new FlickFetchr().fetchRecentPhotos(); } else { items = new FlickFetchr().searchPhotos(query); } if (items.size() == 0) { return Result.FAILURE; } String resultId = items.get(0).getId(); if (resultId.equals(lastResultId)){ Log.i(TAG, "Got an old result: " + resultId); } else { Log.i(TAG, "Got a new result: " + resultId); } QueryPreferences.setLastResultId(getContext(), resultId); Resources resources = getContext().getResources(); Intent i = PhotoGalleryActivity.newIntent(getContext()); PendingIntent pi = PendingIntent.getActivity(getContext(), 0, i, 0); Notification notification = new NotificationCompat.Builder(getContext()) .setTicker(resources.getString(R.string.new_pictures_title)) .setSmallIcon(android.R.drawable.ic_menu_report_image) .setContentTitle(resources.getString(R.string.new_pictures_title)) .setContentText(resources.getString(R.string.new_pictures_text)) .setContentIntent(pi) .build(); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getContext()); notificationManager.notify(0, notification); return Result.SUCCESS; } public static void schedulePeriodic() { new JobRequest.Builder(PollingDataJob.TAG) .setPeriodic(TimeUnit.MINUTES.toMillis(15), TimeUnit.MINUTES.toMillis(5)) .setUpdateCurrent(true) .setPersisted(true) .setRequiredNetworkType(JobRequest.NetworkType.CONNECTED) .build() .schedule(); } public class DemoJobCreator implements JobCreator { @Override public Job create(String tag) { switch (tag) { case PollingDataJob.TAG: return new PollingDataJob(); default: return null; } } } public final class AddReceiver extends JobCreator.AddJobCreatorReceiver { @Override protected void addJobCreator(@NonNull Context context, @NonNull JobManager manager) { Log.e(TAG, "AddReceiverBroadcast"); manager.addJobCreator(new DemoJobCreator()); } } Well, the very place to start the method, which is responsible for all the functionality that I want to perform in deferred time
PollingDataJob.schedulePeriodic(); It seems to me that the whole problem is that the AddReceiver listener does not work and the string for running JobCreator is not executed.