JobSchedulerCompat icon indicating copy to clipboard operation
JobSchedulerCompat copied to clipboard

When the version is different from 21(LOLIPOP), it runs only once and stops.

Open carreiraDesenvolvedor opened this issue 10 years ago • 0 comments

Good night. When I ran the program in KITKAT the program did not go into Loop, run the code only once, but shows no error, just stopped, follows the JobService class, thanks:

public class JobSchedulerService extends JobService {

public static final String TAG = "LOG";

@Override
public boolean onStartJob(JobParameters params) {
    Log.i(TAG, "onStartJob("+params.getExtras().getString("string")+")");
    new MyAsyncTask(this).execute(params);
    return true;
}

@Override
public boolean onStopJob(JobParameters params) {
    Log.i(TAG, "onStopJob()");
    return true;
}

// INNER CLASS
    private static class MyAsyncTask extends AsyncTask<JobParameters, Void, String>{
        private JobSchedulerService jss;

        public MyAsyncTask(JobSchedulerService j){
            jss = j;
        }

        @Override
        protected String doInBackground(JobParameters... params) {
            Log.i(TAG, "doInBackground()");

            SystemClock.sleep(5000);

            String answer = HttpConnection
                                .getSetDataWeb("http://www.villopim.com.br/android/ExampleJobScheduler/get-random.php",
                                        "method");

            jss.jobFinished(params[0], true);

            return answer;
        }
        @Override
        protected void onPostExecute(String s) {
            Log.i(TAG, "onPostExecute()");

            EventBus.getDefault().post( new MessageEB( s ));
        }
    }

}

carreiraDesenvolvedor avatar Jul 01 '15 22:07 carreiraDesenvolvedor