Android.app.job.JobScheduler instead of using WakefulBroadcastReceiver

As described here , the regular WakefulBroadcastReceiver class WakefulBroadcastReceiver deprecated.

So, now it is impossible to create scheduled tasks, for example, for previous releases of the SDK. Google says i should use

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

But how?

So what is the most useful solution for currently scheduled background tasks?

Is AlarmManager no longer useful?

My application wakes up several times a day and updates notifications using AlarmManager. I'm not quite sure what I need to change. What do I need to implement? Old API and new? Or just the most advanced solution?

+5
source share
1 answer

now it is impossible to create scheduled tasks, for example, for previous releases of the SDK

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

But how?

Um, JobScheduler covered in JavaDocs and elsewhere in the documentation , as well as books and courses on developing applications for Android.

what is the most useful solution for background scheduled tasks currently?

It completely depends on how you want to define "useful", and I do not know your definition.

Generally speaking:

  • Use JobScheduler where possible

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

  • Use other set...() methods on AlarmManager for backward compatibility for devices up to Android 5.0, possibly through a wrapper library (e.g. Evernote android-job )

  • Use push messaging (e.g. FCM) where possible, and if you are dependent on this push messaging solution

Is AlarmManager no longer useful?

Performing any periodic background work is "no longer useful" for some definitions of "useful." Standby mode and standby mode of the application, introduced in Android 6.0, basically do work against the background of unreasonable work from the point of view of the user.

What do I need to implement? Old API and new? Or just the most modern solution?

It is impossible to answer this abstractly. There is nothing in Android 8.0 or in the support library, which prevents you from using AlarmManager as you were.

+4
source

Source: https://habr.com/ru/post/1271368/


All Articles