Using a Timer every 5 second in a service, that the service whos call by a receiver
<p>I make a receiver that work, and this is the code:</p>

<pre><code>public class ServicioCargado extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) 
    {
        if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
            Intent i = new Intent();
            i.setAction("mauricio.androids.smsprojects.MyService");
            context.startService(i);
        }
    }

}
</code></pre>

<p>and this is my service, he is created by the receiver but is close automate, and i dont want that, i want the timer keep running, and execute every 5 seconds, i dont see the problem, thank for all</p>

<pre><code>public class MyService extends Service {

    private MyService actual=null;

    private Timer timer = new Timer();
    private static final long UPDATE_INTERVAL = 5000;
    //private final IBinder mBinder = new MyBinder();

    @Override
    public IBinder onBind(Intent arg0) {
          return null;
    }
    @Override
    public void onCreate() {
          super.onCreate();
          //Hacemos un while que cada cierto tiempo haga algo o un sleep
          Toast.makeText(this,"Se esta ejecutando el programa para enviar sms", Toast.LENGTH_SHORT).show();
          actual=this;
          Log.d("Mauricio", "Creando servicio");
          Toast.makeText(this,"Antes de ejecutar el timer", Toast.LENGTH_SHORT).show();
          MyTimerExecution();
          Toast.makeText(this,"Despues de ejecutar el timer", Toast.LENGTH_SHORT).show();
        }

    private void MyTimerExecution() {
        timer.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                // Imagine here a freaking cool web access ;-)
                //Toast.makeText(actual,"Service update ...", Toast.LENGTH_SHORT).show();
                Log.d("Mauricio","aqui");
            }
        }, 0, UPDATE_INTERVAL);
    }

    @Override
    public void onDestroy() {
          super.onDestroy();
          if (timer != null) {
            timer.cancel();
        }
        Toast.makeText(this, "Service destroyed ...", Toast.LENGTH_LONG).show();
    }
}
</code></pre>
