Check Mobile App
Read now

Intro to exploring Background Execution Limits on Android Oreo Using JobScheduler API

Save

Hello All, as we all know that Whenever an app runs in the background, it consumes some of the device’s limited resources, like RAM. To improve the user experience, Android 8.0 (API level 26) imposes limitations on what apps can do while running in the background.

In Oreo devices, you can run the background task using service. So follow the steps:-

  1. Create a JobScheduler and JobService.
  2. Create a Broadcast Receiver.
  3. And A service for executing a background task.

You can get more about details using the following code snippets.

Creation of JobScheduler and Job Service

The Android 5.0 Lollipop (API 21) release introduces a job scheduler API via the JobScheduler class. This API allows to batch jobs when the device has more resources available. In general, this API can be used to schedule everything that is not time critical for the user. A unit of work is encapsulated by a JobInfo object. This object specifies the scheduling criteria. The job scheduler allows considering the state of the device. To implement a Job, extend the JobService class and implement the onStartJob and onStopJob methods. If the job fails for some reason, return true from on the onStopJob to restart the job. The onStartJob is performed in the main thread, if you start asynchronous processing in this method, return true otherwise false.The new JobService must be registered in the Android manifest with the BIND_JOB_SERVICE permission.

Create a Broadcast Receiver

Here, we are implementing a broadcast receiver in order to trigger the jobScheduler implementation.

Create A service

From the JobService, we are triggering the execution of a Service background task.

You can go throw the following link get more details and find more way to resolve background limitation:-

https://medium.com/exploring-android/exploring-background-execution-limits-on-android-oreo-ab384762a66c

https://developer.android.com/guide/background/

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


1 comments

  • Ruban Thiraviyaraj J
    How do Execute in Main Activity
  • css.php

    Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!

    Deniel Kerr

    Owner and Founder. Opencart

    Talk to Sales
    Start a Project

      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home