Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android.app.job.JobScheduler instead of WakefulBroadcastReceiver usage

As here described the usual class WakefulBroadcastReceiver is deprecated.

So, now this is not possible to create a scheduled tasks like for previous SDK releases. Google says, I have to use

https://developer.android.com/reference/android/app/job/JobScheduler.html

But how?

So, what's the most useful solution for background scheduled tasks nowadays?

Is AlarmManager not longer useful?

My application wakes up several times a day and updates the notifications using AlarmManager. I'm not really sure what I have to change. What I have to implement? The old API and a new one? Or only up-to-date solution?

like image 758
Vyacheslav Avatar asked Aug 30 '17 15:08

Vyacheslav


1 Answers

now this is not possible to create a scheduled tasks like for previous SDK releases

WakefulBroadcastReceiver has never been the sole option for this. For example, my WakefulIntentService dates back to 2009. And the JobIntentService added to the support library supplants both of those.

But how?

Um, JobScheduler is covered in the JavaDocs and elsewhere in the documentation, as well as books and courses on Android app development.

what's the most useful solution for background scheduled tasks nowadays?

That depends entirely upon how you want to define "useful", and I don't know your definition.

Generally speaking:

  • Use JobScheduler where possible

  • Use setAlarmClock() on AlarmManager if you are writing an alarm clock app

  • Use the other set...() methods on AlarmManager for backwards compatibility for pre-Android 5.0 devices, perhaps via a wrapper library (e.g., Evernote's android-job)

  • Use push messaging (e.g., FCM) where practical and if you are in position to be dependent upon that push messaging solution

Is AlarmManager not longer useful?

Doing any sort of periodic background work is "no longer useful" for some definitions of "useful". Doze mode and app standby, introduced in Android 6.0, basically make periodic background work unreliable from the user's standpoint.

What I have to implement? The old API and a new one? Or only up-to-date solution?

It is impossible to answer that in the abstract. There is nothing in Android 8.0, or the support library, that prevents you from using AlarmManager as you have been.

like image 177
CommonsWare Avatar answered Sep 30 '22 13:09

CommonsWare