FileDocCategorySizeDatePackage
TestJobService.javaAPI DocAndroid 5.1 API4279Thu Mar 12 22:22:44 GMT 2015com.android.demo.jobSchedulerApp.service

TestJobService

public class TestJobService extends android.app.job.JobService
Service to handle sync requests.

This service is invoked in response to Intents with action android.content.SyncAdapter, and returns a Binder connection to SyncAdapter.

For performance, only one sync adapter will be initialized within this application's context.

Note: The SyncService itself is not notified when a new sync occurs. It's role is to manage the lifecycle of our and provide a handle to said SyncAdapter to the OS on request.

Fields Summary
private static final String
TAG
static int
currentId
com.android.demo.jobSchedulerApp.MainActivity
mActivity
private final android.util.SparseArray
jobParamsMap
Constructors Summary
Methods Summary
public booleancallJobFinished()

        if (jobParamsMap.size() == 0) {
            return false;
        }
        JobParameters params = jobParamsMap.valueAt(0);
        if (params == null) {
            return false;
        } else {
            jobFinished(params, false);
            jobParamsMap.removeAt(0);
            return true;
        }
    
public voidonCreate()


    
       
        super.onCreate();
        Log.i(TAG, "Service created");
    
public voidonDestroy()

        super.onDestroy();
        Log.i(TAG, "Service destroyed");
    
public intonStartCommand(android.content.Intent intent, int flags, int startId)

        Messenger callback = intent.getParcelableExtra("messenger");
        Message m = Message.obtain();
        m.what = MainActivity.MSG_SERVICE_OBJ;
        m.obj = this;
        try {
            callback.send(m);
        } catch (RemoteException e) {
            Log.e(TAG, "Error passing service object back to activity.");
        }
        return START_NOT_STICKY;
    
public booleanonStartJob(android.app.job.JobParameters params)

        Log.i(TAG, "on start job: " + params.getJobId());
        currentId++;
        jobParamsMap.put(currentId, params);
        final int currId = this.currentId;
        if (mActivity != null) {
            mActivity.onReceivedStartJob(params);
        }

        Toast.makeText(
                this, "On start job: '" + params.getJobId() + "' deadline exceeded: " +
                        params.isOverrideDeadlineExpired(),
                Toast.LENGTH_LONG).show();

        return true;
    
public booleanonStopJob(android.app.job.JobParameters params)

        Log.i(TAG, "on stop job: " + params.getJobId());
        int ind = jobParamsMap.indexOfValue(params);
        jobParamsMap.remove(ind);
        mActivity.onReceivedStopJob();
        return false; // no reschedule
    
public voidscheduleJob(android.app.job.JobInfo job)
Send job to the JobScheduler.

        Log.d(TAG, "Scheduling job " + job);
        JobScheduler tm =
                (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
        tm.schedule(job);
    
public voidsetUiCallback(com.android.demo.jobSchedulerApp.MainActivity activity)



        
        mActivity = activity;