android - postDelayed() in a Service -


i'm trying restart service in few time. code looks (inside onstartcommand(...))

looper.prepare(); handler handler = new handler(); handler.postdelayed(new runnable() {             @override             public void run() {                 intent intent = new intent(backgroundservice.this, backgroundservice.class);                 startservice(intent);             }         }, 3 * 60000); 

service running in foreground while code executes, doesn't seem call onstartcommand(...) . there other way restart service in few time?

upd: i've found out restarts service, not in given time (may take 30 minutes instead of given 3). question how make restart consequently

i declare handler variable @ service level, not locally in onstartcommand, like:

public class nlservice extends notificationlistenerservice {     handler handler = new handler();       @override     public int onstartcommand(intent intent, int flags, int startid) {         handler.postdelayed(new runnable() {....} , 60000);     } 

and service has own loop, not need looper.prepare();


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -