com.evernote.android.job.JobManager Java Examples
The following examples show how to use
com.evernote.android.job.JobManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XDripJobCreator.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
/** * All new Job classes need to be included in the factory method below */ @Override @Nullable public Job create(@NonNull final String tag) { if (D) UserError.Log.ueh("JobCreator", JoH.dateTimeText(JoH.tsl()) + " Passed: " + tag); switch (tag) { /* case CloudSyncJob.TAG: return new CloudSyncJob(); */ case DailyJob.TAG: return new DailyJob(); default: UserError.Log.wtf(TAG, "Failed to match Job: " + tag + " requesting cancellation"); try { JobManager.instance().cancelAllForTag(tag); } catch (Exception e) { // } return null; } }
Example #2
Source File: XDripJobCreator.java From xDrip with GNU General Public License v3.0 | 6 votes |
/** * All new Job classes need to be included in the factory method below */ @Override @Nullable public Job create(@NonNull final String tag) { if (D) UserError.Log.ueh("JobCreator", JoH.dateTimeText(JoH.tsl()) + " Passed: " + tag); switch (tag) { /* case CloudSyncJob.TAG: return new CloudSyncJob(); */ case DailyJob.TAG: return new DailyJob(); default: UserError.Log.wtf(TAG, "Failed to match Job: " + tag + " requesting cancellation"); try { JobManager.instance().cancelAllForTag(tag); } catch (Exception e) { // } return null; } }
Example #3
Source File: AndroidJobStrategy.java From cloudinary_android with MIT License | 6 votes |
/** * {@inheritDoc} */ @Override public void executeRequestsNow(int howMany) { int started = 0; for (JobRequest jobRequest : JobManager.instance().getAllJobRequests()) { if (isSoonButNotImmediate(jobRequest)) { JobRequest.Builder builder = jobRequest.cancelAndEdit(); long endMillis = Math.max(jobRequest.getEndMs(), RUN_NOW_TIME_WINDOW_END); builder.setExecutionWindow(RUN_NOW_TIME_WINDOW_START, endMillis).build().schedule(); started++; } if (started == howMany) { break; } } Logger.d(TAG, String.format("Job scheduled started %d requests.", started)); }
Example #4
Source File: BackgroundTaskModule.java From react-native-background-task with MIT License | 6 votes |
@Override public void initialize() { Log.d(TAG, "Initializing"); super.initialize(); // Read in an existing scheduled job if there is one Set<JobRequest> jobRequests = JobManager.instance().getAllJobRequests(); if (jobRequests.size() > 1) { Log.w(TAG, "Found " + jobRequests.size() + " scheduled jobs, expecting 0 or 1"); } if (!jobRequests.isEmpty()) { mJobRequest = jobRequests.iterator().next(); } // Hook into lifecycle events so we can tell when the application is foregrounded ReactApplicationContext context = getReactApplicationContext(); context.addLifecycleEventListener(this); }
Example #5
Source File: MainApplication.java From OneTapVideoDownload with GNU General Public License v3.0 | 6 votes |
@Override public void onCreate() { super.onCreate(); JobManager.create(this).addJobCreator(new HookFetchJobCreator()); int noOfJobRequests = JobManager.instance().getAllJobRequestsForTag(HookFetchJob.TAG).size(); // No of Job Requests for HookFetchJob would be greater than 1 for older version of // application because of rescheduling of job again and again, causing large no. of wakelocks if (noOfJobRequests > 1) { JobManager.instance().cancelAllForTag(HookFetchJob.TAG); noOfJobRequests = 0; } if (noOfJobRequests == 0) { HookFetchJob.scheduleJob(); } }
Example #6
Source File: BottinSyncJob.java From ETSMobile-Android2 with Apache License 2.0 | 6 votes |
/** * Schedule a job if the job hasn't been already scheduled * Returns the jobId. Returns -1 if no job has been created. * * @return the jobId */ public static int scheduleJob() { int jobId = -1; Set<JobRequest> jobRequests = JobManager.instance().getAllJobRequestsForTag(TAG); if (jobRequests.isEmpty()) { jobId = new JobRequest.Builder(TAG) .setPeriodic(TimeUnit.DAYS.toMillis(1)) .setRequiredNetworkType(JobRequest.NetworkType.CONNECTED) .setRequiresBatteryNotLow(true) .setRequirementsEnforced(true) .setUpdateCurrent(true) .build() .schedule(); } else { for (JobRequest jobRequest : jobRequests) { Log.d(TAG, "Job already scheduled! JobId: " + jobRequest.getJobId() + ". Interval (ms): " + jobRequest.getIntervalMs() + ". Last run: " + jobRequest.getLastRun()); } } return jobId; }
Example #7
Source File: App.java From android-job with Apache License 2.0 | 6 votes |
@Override public void onCreate() { super.onCreate(); Stetho.initializeWithDefaults(this); if (BuildConfig.DEBUG) { StrictMode.setThreadPolicy( new StrictMode.ThreadPolicy.Builder() .detectAll() .penaltyLog() .penaltyDeath() .build()); StrictMode.setVmPolicy( new StrictMode.VmPolicy.Builder() .detectAll() .penaltyLog() .penaltyDeath() .build()); } JobManager.create(this).addJobCreator(new DemoJobCreator()); }
Example #8
Source File: MainActivity.java From android-job with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mJobManager = JobManager.instance(); if (savedInstanceState != null) { mLastJobId = savedInstanceState.getInt(LAST_JOB_ID, 0); } CompoundButton enableGcm = findViewById(R.id.enable_gcm); mRequiresCharging = findViewById(R.id.check_requires_charging); mRequiresDeviceIdle = findViewById(R.id.check_requires_device_idle); mNetworkTypeSpinner = findViewById(R.id.spinner_network_type); ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, getNetworkTypesAsString()); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mNetworkTypeSpinner.setAdapter(adapter); enableGcm.setChecked(JobConfig.isApiEnabled(JobApi.GCM)); enableGcm.setEnabled(JobApi.GCM.isSupported(this)); enableGcm.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { JobConfig.setApiEnabled(JobApi.GCM, isChecked); } }); }
Example #9
Source File: TimesBroadcastReceiver.java From prayer-times-android with Apache License 2.0 | 5 votes |
@Override public void onStart() { JobManager.create(App.get()).addJobCreator(new SyncJobCreator()); try { Times.getTimes(); } catch (Exception e) { Crashlytics.logException(e); } InternalBroadcastReceiver.sender(App.get()).sendTimeTick(); LocationReceiver.start(App.get()); Times.setAlarms(); }
Example #10
Source File: HavenApp.java From haven with GNU General Public License v3.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); mPrefs = new PreferenceManager(this); ImagePipelineConfig.Builder b = ImagePipelineConfig.newBuilder(this); ImagePipelineConfig config = b .setProgressiveJpegConfig(new SimpleProgressiveJpegConfig()) .setResizeAndRotateEnabledForNetwork(true) .setDownsampleEnabled(true) .build(); Fresco.initialize(this,config); try { ImagePipelineNativeLoader.load(); } catch (UnsatisfiedLinkError e) { Fresco.shutDown(); b.experiment().setNativeCodeDisabled(true); config = b.build(); Fresco.initialize(this, config); e.printStackTrace(); } AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); if (mPrefs.getRemoteAccessActive()) startServer(); havenApp = this; dataBaseInstance = HavenEventDB.getDatabase(this); JobManager.create(this).addJobCreator(new HavenJobCreator()); }
Example #11
Source File: BackgroundTaskModule.java From react-native-background-task with MIT License | 5 votes |
private void commitSchedule() { Log.d(TAG, "Committing job schedule"); // Cancel any previous job JobManager.instance().cancelAll(); // Schedule the new job, if the user has provided some config if (mJobRequest != null) { mJobRequest.schedule(); } }
Example #12
Source File: BackgroundTaskModule.java From react-native-background-task with MIT License | 5 votes |
/** * Allow the JS users to cancel the previously scheduled task. */ @ReactMethod public void cancel() { Log.d(TAG, "@ReactMethod BackgroundTask.cancel"); mJobRequest = null; JobManager.instance().cancelAll(); }
Example #13
Source File: WebTimes.java From prayer-times-android with Apache License 2.0 | 5 votes |
private void scheduleJob() { int syncedDays = getSyncedDays(); JobManager.create(App.get()); if (syncedDays == 0 && System.currentTimeMillis() - lastSync < 1000 * 60 * 60) { lastSync = System.currentTimeMillis(); if (App.isOnline()) syncAsync(); else jobId = new JobRequest.Builder(SyncJob.TAG + getID()).setExecutionWindow(1, TimeUnit.MINUTES.toMillis(3)) .setRequiredNetworkType(JobRequest.NetworkType.CONNECTED) .setBackoffCriteria(TimeUnit.MINUTES.toMillis(3), JobRequest.BackoffPolicy.EXPONENTIAL).setUpdateCurrent(true).build() .schedule(); } else if (syncedDays < 3) jobId = new JobRequest.Builder(SyncJob.TAG + getID()).setExecutionWindow(1, TimeUnit.HOURS.toMillis(3)) .setRequiredNetworkType(JobRequest.NetworkType.CONNECTED).setUpdateCurrent(true) .setBackoffCriteria(TimeUnit.HOURS.toMillis(1), JobRequest.BackoffPolicy.EXPONENTIAL).build().schedule(); else if (syncedDays < 10) jobId = new JobRequest.Builder(SyncJob.TAG + getID()).setExecutionWindow(1, TimeUnit.DAYS.toMillis(3)) .setBackoffCriteria(TimeUnit.DAYS.toMillis(1), JobRequest.BackoffPolicy.LINEAR) .setRequiredNetworkType(JobRequest.NetworkType.CONNECTED).setRequiresCharging(true).setUpdateCurrent(true).build().schedule(); else if (syncedDays < 20) jobId = new JobRequest.Builder(SyncJob.TAG + getID()).setExecutionWindow(1, TimeUnit.DAYS.toMillis(10)) .setRequiredNetworkType(JobRequest.NetworkType.UNMETERED) .setBackoffCriteria(TimeUnit.DAYS.toMillis(3), JobRequest.BackoffPolicy.LINEAR).setUpdateCurrent(true).build().schedule(); }
Example #14
Source File: FGApplication.java From fingen with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public void onCreate() { // Debug.startMethodTracing("Startup"); super.onCreate(); sAppComponent = DaggerAppComponent.builder() .contextModule(new ContextModule(this)) .build(); mContext = this; JobManager.create(this).addJobCreator(new BackupJobCreator()); JobManager.create(this).addJobCreator(new BackupTestJobCreator()); mUpdateUIHandler = new UpdateUIHandler(this); mAppPaused = true; LockManager<CustomPinActivity> lockManager = LockManager.getInstance(); lockManager.enableAppLock(this, CustomPinActivity.class); lockManager.getAppLock().setOnlyBackgroundTimeout(true); lockManager.getAppLock().setLogoId(R.drawable.ic_main); long timeout = Integer.valueOf( PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString( FgConst.PREF_PIN_LOCK_TIMEOUT, "10"))*1000; lockManager.getAppLock().setTimeout(timeout); lockManager.getAppLock().setOnlyBackgroundTimeout(true); registerActivityLifecycleCallbacks(new FgActivityLifecycleCallbacks()); mCustomIntentReceiver = new CustomIntentReceiver(); BackupJob.schedule(); }
Example #15
Source File: MainActivity.java From ETSMobile-Android2 with Apache License 2.0 | 5 votes |
private void initJobManager() { JobManager.create(this).addJobCreator(new JobCreator() { @Override public Job create(String tag) { if (tag.equals(BottinSyncJob.TAG)) return new BottinSyncJob(); else return null; } }); }
Example #16
Source File: PlatformJobService.java From android-job with Apache License 2.0 | 5 votes |
@Override public boolean onStopJob(JobParameters params) { Job job = JobManager.create(this).getJob(params.getJobId()); if (job != null) { job.cancel(); CAT.d("Called onStopJob for %s", job); } else { CAT.d("Called onStopJob, job %d not found", params.getJobId()); } // do not reschedule return false; }
Example #17
Source File: PlatformWorker.java From android-job with Apache License 2.0 | 5 votes |
@Override public void onStopped() { int jobId = getJobId(); Job job = JobManager.create(getApplicationContext()).getJob(jobId); if (job != null) { job.cancel(); CAT.d("Called onStopped for %s", job); } else { CAT.d("Called onStopped, job %d not found", jobId); } }
Example #18
Source File: PlatformGcmService.java From android-job with Apache License 2.0 | 5 votes |
@Override public void onInitializeTasks() { super.onInitializeTasks(); /* * When the app is being updated, then all jobs are cleared in the GcmNetworkManager. The manager * calls this method to reschedule. Let's initialize the JobManager here, which will reschedule * jobs manually. */ try { JobManager.create(getApplicationContext()); } catch (JobManagerCreateException ignored) { } }
Example #19
Source File: TimesBroadcastReceiver.java From prayer-times-android with Apache License 2.0 | 5 votes |
@Override public void onStart() { JobManager.create(App.get()).addJobCreator(new SyncJobCreator()); try { Times.getTimes(); } catch (Exception e) { Crashlytics.logException(e); } InternalBroadcastReceiver.sender(App.get()).sendTimeTick(); LocationReceiver.start(App.get()); Times.setAlarms(); }
Example #20
Source File: WebTimes.java From prayer-times-android with Apache License 2.0 | 5 votes |
private void scheduleJob() { int syncedDays = getSyncedDays(); JobManager.create(App.get()); if (syncedDays == 0 && System.currentTimeMillis() - lastSync < 1000 * 60 * 60) { lastSync = System.currentTimeMillis(); if (App.isOnline()) syncAsync(); else jobId = new JobRequest.Builder(SyncJob.TAG + getID()).setExecutionWindow(1, TimeUnit.MINUTES.toMillis(3)) .setRequiredNetworkType(JobRequest.NetworkType.CONNECTED) .setBackoffCriteria(TimeUnit.MINUTES.toMillis(3), JobRequest.BackoffPolicy.EXPONENTIAL).setUpdateCurrent(true).build() .schedule(); } else if (syncedDays < 3) jobId = new JobRequest.Builder(SyncJob.TAG + getID()).setExecutionWindow(1, TimeUnit.HOURS.toMillis(3)) .setRequiredNetworkType(JobRequest.NetworkType.CONNECTED).setUpdateCurrent(true) .setBackoffCriteria(TimeUnit.HOURS.toMillis(1), JobRequest.BackoffPolicy.EXPONENTIAL).build().schedule(); else if (syncedDays < 10) jobId = new JobRequest.Builder(SyncJob.TAG + getID()).setExecutionWindow(1, TimeUnit.DAYS.toMillis(3)) .setBackoffCriteria(TimeUnit.DAYS.toMillis(1), JobRequest.BackoffPolicy.LINEAR) .setRequiredNetworkType(JobRequest.NetworkType.CONNECTED).setRequiresCharging(true).setUpdateCurrent(true).build().schedule(); else if (syncedDays < 20) jobId = new JobRequest.Builder(SyncJob.TAG + getID()).setExecutionWindow(1, TimeUnit.DAYS.toMillis(10)) .setRequiredNetworkType(JobRequest.NetworkType.UNMETERED) .setBackoffCriteria(TimeUnit.DAYS.toMillis(3), JobRequest.BackoffPolicy.LINEAR).setUpdateCurrent(true).build().schedule(); }
Example #21
Source File: AndroidJobStrategy.java From cloudinary_android with MIT License | 5 votes |
/** * {@inheritDoc} */ @Override public int cancelAllRequests() { Logger.i(TAG, "All requests cancelled."); int count = JobManager.instance().cancelAll(); killAllThreads(); return count; }
Example #22
Source File: AndroidJobStrategy.java From cloudinary_android with MIT License | 5 votes |
/** * {@inheritDoc} */ @Override public int getPendingImmediateJobsCount() { int pending = 0; for (JobRequest jobRequest : JobManager.instance().getAllJobRequests()) { if (isImmediate(jobRequest)) { pending++; } } return pending; }
Example #23
Source File: AndroidJobStrategy.java From cloudinary_android with MIT License | 5 votes |
/** * {@inheritDoc} */ @Override public int getRunningJobsCount() { int running = 0; for (Job job : JobManager.instance().getAllJobs()) { if (!job.isFinished()) { running++; } } return running; }
Example #24
Source File: NotificationsJobCreator.java From ForPDA with GNU General Public License v3.0 | 4 votes |
@Override protected void addJobCreator(@NonNull Context context, @NonNull JobManager manager) { // manager.addJobCreator(new NotificationsJobCreator()); }
Example #25
Source File: DemoJobCreator.java From android-job with Apache License 2.0 | 4 votes |
@Override protected void addJobCreator(@NonNull Context context, @NonNull JobManager manager) { // manager.addJobCreator(new DemoJobCreator()); }
Example #26
Source File: WebTimes.java From prayer-times-android with Apache License 2.0 | 4 votes |
@Override public void delete() { super.delete(); if (jobId != -1) JobManager.instance().cancel(jobId); }
Example #27
Source File: WebTimes.java From prayer-times-android with Apache License 2.0 | 4 votes |
@Override public void delete() { super.delete(); if (jobId != -1) JobManager.instance().cancel(jobId); }
Example #28
Source File: AndroidJobStrategy.java From cloudinary_android with MIT License | 4 votes |
/** * {@inheritDoc} */ @Override public void init(Context context) { JobManager.create(context).addJobCreator(new JobCreator()); }
Example #29
Source File: xdrip.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
@Override public void onCreate() { xdrip.context = getApplicationContext(); super.onCreate(); try { if (PreferenceManager.getDefaultSharedPreferences(xdrip.context).getBoolean("enable_crashlytics", true)) { initCrashlytics(this); initBF(); } } catch (Exception e) { Log.e(TAG, e.toString()); } executor = new PlusAsyncExecutor(); PreferenceManager.setDefaultValues(this, R.xml.pref_general, true); PreferenceManager.setDefaultValues(this, R.xml.pref_data_sync, true); PreferenceManager.setDefaultValues(this, R.xml.pref_advanced_settings, true); PreferenceManager.setDefaultValues(this, R.xml.pref_notifications, true); PreferenceManager.setDefaultValues(this, R.xml.pref_data_source, true); PreferenceManager.setDefaultValues(this, R.xml.xdrip_plus_defaults, true); PreferenceManager.setDefaultValues(this, R.xml.xdrip_plus_prefs, true); checkForcedEnglish(xdrip.context); JoH.ratelimit("policy-never", 3600); // don't on first load new IdempotentMigrations(getApplicationContext()).performAll(); JobManager.create(this).addJobCreator(new XDripJobCreator()); DailyJob.schedule(); //SyncService.startSyncServiceSoon(); if (!isRunningTest()) { MissedReadingService.delayedLaunch(); NFCReaderX.handleHomeScreenScanPreference(getApplicationContext()); AlertType.fromSettings(getApplicationContext()); //new CollectionServiceStarter(getApplicationContext()).start(getApplicationContext()); CollectionServiceStarter.restartCollectionServiceBackground(); PlusSyncService.startSyncService(context, "xdrip.java"); if (Pref.getBoolean("motion_tracking_enabled", false)) { ActivityRecognizedService.startActivityRecogniser(getApplicationContext()); } BluetoothGlucoseMeter.startIfEnabled(); LeFunEntry.initialStartIfEnabled(); MiBandEntry.initialStartIfEnabled(); BlueJayEntry.initialStartIfEnabled(); XdripWebService.immortality(); VersionTracker.updateDevice(); } else { Log.d(TAG, "Detected running test mode, holding back on background processes"); } Reminder.firstInit(xdrip.getAppContext()); PluggableCalibration.invalidateCache(); }
Example #30
Source File: JobsModule.java From Building-Professional-Android-Applications with MIT License | 4 votes |
@Provides @Singleton JobManager provideJobManager(Application application, AppJobCreator jobCreator) { JobManager.create(application).addJobCreator(jobCreator); return JobManager.instance(); }