Dr.Noname
Dr.Noname

Reputation: 73

Doing something in sleep mode

I check for new messages in the site by using the JSON

Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(new Runnable() {

public void run() {
                notif();              
                }

             }, 0, 60, TimeUnit.SECONDS);

But the check does not work in sleep mode. Than it is possible to replace?

Upvotes: 1

Views: 104

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007658

If your minSdkVersion is 21 or higher, use JobScheduler.

If your minSdkVersion is below 21, and you are tied into using the Play Services SDK for other reasons, use firebase-job-dispatcher.

If your minSdkVersion is below 21, and you would prefer not to be tied into using the Play Services SDK, use Evernote's android-job library, which uses JobScheduler where it can and gracefully degrades to AlarmManager where it cannot.

Bear in mind that Doze mode and app standby, on Android 6.0+, will prevent you from doing periodic work, except during device-defined "idle maintenance windows", which may be once every few hours.

You can read more about scheduled work in the documentation.

Upvotes: 2

Related Questions