Service with temperature sensor

Hi, do someone know how could I make  this service to read the temperature each 10 seconds and then show it on the log?
public class Servicio extends JobService {

@Override
public boolean onStartJob(JobParameters params) {

return false;
}

@Override
public boolean onStopJob(JobParameters params) {

return false;
}
private Handler mJobHandler = new Handler(new Handler.Callback() {

@Override
public boolean handleMessage( Message msg ) {
Toast.makeText( getApplicationContext(),
"JobService task running", Toast.LENGTH_SHORT )
.show();
jobFinished( (JobParameters) msg.obj, false );
return true;
}

} );
}

Comments

  • Already done, the code is below here if someone needs it:
    public class YourService extends JobService {

    @Override
    public boolean onStartJob(JobParameters params) {
    mJobHandler.sendMessage( Message.obtain( mJobHandler, 1, params ) );
    return true;
    }

    @Override
    public boolean onStopJob(JobParameters params) {

    return false;
    }
    private Handler mJobHandler = new Handler(new Handler.Callback() {

    @Override
    public boolean handleMessage( Message msg ) {
    Toast.makeText( getApplicationContext(),
    "JobService task running", Toast.LENGTH_SHORT )
    .show();
    jobFinished( (JobParameters) msg.obj, false );
    return true;
    }

    } );
    }
  • edited April 2017
    now I want the Handler to read the temperature and the accelerometer just one time, the code is the same as I put before with the Service. Any Idea?
This discussion has been closed.