android - How to call another activity after destroy() of service is called -


in code have created service.after 3 seconds want destory service , want call activity in destroy method.but doesnt seem work.

public class timerservice extends service  {     @override     public ibinder onbind(intent intent)     {         return null;     }      @override     public void oncreate()     {         super.oncreate();     }      @override     public int onstartcommand(intent intent,int flags,int startid)     {               new countdowntimer(3000, 1000)          {              public void ontick(long millisuntilfinished)             {              }             public void onfinish()             {                  stopself();             }         }.start();          return super.onstartcommand(intent,flags,startid);     }      @override     public void ondestroy()     {         super.ondestroy();         intent = new intent(this,dummy.class);         i.putextra("sessiontimedout","expire");         i.addflags(intent.flag_activity_new_task);         getapplication().startactivity(i);      } } 

activity calls service

public class mainactivity extends activity  {     @override     protected void oncreate(bundle savedinstancestate)     {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         intent = new intent(this,timerservice.class);         startservice(i);     } } 

try insert code finish method:

 @override public int onstartcommand(intent intent,int flags,int startid) {           new handler().postdelayed(new runnable() {         @override         public void run() {             intent = new intent(this,dummy.class);             i.putextra("sessiontimedout","expire");             i.addflags(intent.flag_activity_new_task);             startactivity(i);             stopself();         }     }, 3000);      return super.onstartcommand(intent,flags,startid); } 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -