I, i have a service and i want that once it started, it performs is work every 30 seconds. How can i do that?
Tnk Valerio
I, i have a service and i want that once it started, it performs is work every 30 seconds. How can i do that?
Tnk Valerio
Handler usage example for your Service (Bind part of the Service is missing):
import android.app.Service;
import android.os.Handler;
public class PeriodicService extends Service {
private Handler mPeriodicEventHandler;
private final int PERIODIC_EVENT_TIMEOUT = 30000;
@Override
public void onCreate() {
super.onCreate();
mPeriodicEventHandler = new Handler();
mPeriodicEventHandler.postDelayed(doPeriodicTask, PERIODIC_EVENT_TIMEOUT);
}
private Runnable doPeriodicTask = new Runnable()
{
public void run()
{
//your action here
mPeriodicEventHandler.postDelayed(doPeriodicTask, PERIODIC_EVENT_TIMEOUT);
}
};
@Override
public void onDestroy() {
mPeriodicEventHandler.removeCallbacks(doPeriodicTask);
super.onDestroy();
}
}
Maybe this link helps you:
http://stackoverflow.com/questions/1520887/how-to-pause-sleep-thread-or-process-in-android