Set Jobservice Android Runtime

Asked

Viewed 150 times

0

Hello, I need to implement a Jobservice on Android.

I created the base class for a Job, but I’m not able to define an execution parameter, minutes, days and hours etc.

I find no example, someone already implemented and could help me?

public class InformarLocalizacao extends JobService {


@Override
public boolean onStartJob(JobParameters params) {
    return false;
}

@Override
public boolean onStopJob(JobParameters params) {
    return false;
}

}

The <ervice> was added to the manifest, but I need a routine to be called time-in-time...

1 answer

3

To launch Jobservice you must use the Jobscheduler providing you with a Jobinfo.

It is Jobinfo who informs Jobscheduler when Jobservice should be run.

Jobinfo defines a set of rules that indicate when and what conditions should be verified for Jobservice to be launched.

When is indicated with setMinimumLatency() and setOverrideDeadline(), and the periodicity with setPeriodic().
Several conditions may be imposed, including whether or not the device is charging and/or being used.
Jobinfo is built using a Jobinfo.Builder.

Note that the purpose of Jobscheduler is not to perform tasks in given time(date)(a).

  • The point is that the version I need to implement is Jelly Bean, Jobservice works only from Lollipop. There are numerous compatibility solutions. You can tell me the best?

  • Maybe the Workmanager, but it depends on what you want to do. See this reply

  • Try the Firebase Job Dispatcher https://github.com/firebase/firebase-jobdispatcher-android#user-content-firebase-jobdispatcher-

  • It worked with Firebasejobdispatcher Thanks.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.