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?
WakefulBroadcastReceiver
has never been the sole option for this. For example, myWakefulIntentService
dates back to 2009. And theJobIntentService
added to the support library supplants both of those.Um,
JobScheduler
is covered in the JavaDocs and elsewhere in the documentation, as well as books and courses on Android app development.That depends entirely upon how you want to define "useful", and I don't know your definition.
Generally speaking:
Use
JobScheduler
where possibleUse
setAlarmClock()
onAlarmManager
if you are writing an alarm clock appUse the other
set...()
methods onAlarmManager
for backwards compatibility for pre-Android 5.0 devices, perhaps via a wrapper library (e.g., Evernote'sandroid-job
)Use push messaging (e.g., FCM) where practical and if you are in position to be dependent upon that push messaging solution
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.
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.