/**
* Simple receiver that will handle the boot completed intent and send the intent to
* launch the BootDemoService.
* @author BMB
*
*/
public class BootDemoReceiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, final Intent bootintent) {
Intent mServiceIntent = new Intent();
mServiceIntent.setAction("com.enea.training.bootdemo.BootDemoService");
context.startService(mServiceIntent);
}
}
/**
* Simple demo service that schedules a timer task to write something to
* the log at regular intervals.
* @author BMB
*
*/
public class BootDemoService extends Service {
/**
* Delay until first exeution of the Log task.
*/
private final long mDelay = 0;
/**
* Period of the Log task.
*/
private final long mPeriod = 500;
/**
* Log tag for this service.
*/
private final String LOGTAG = "BootDemoService";
/**
* Timer to schedule the service.
*/
private Timer mTimer;
/**
* Implementation of the timer task.
*/
private class LogTask extends TimerTask {
public void run() {
Log.i(LOGTAG, "scheduled");
}
}
private LogTask mLogTask;
@Override
public IBinder onBind(final Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
Log.i(LOGTAG, "created");
mTimer = new Timer();
mLogTask = new LogTask();
}