Use the Service class and implement a thread scheduler inside the service class that will send a request every 5 seconds. The following is an ecode snippet:
public class ProcessingService extends Service { private Timer timer = new Timer(); @Override public IBinder onBind(Intent intent) { return null; } @Override public void onCreate() { super.onCreate(); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { sendRequest(); } }, 0, 5000;
source share