android - Why Thread.sleep() from Service is not working? -


my code :

   callreader.speak("incoming call  "                                         + contactname,                                  texttospeech.queue_add, null);                                 backnormalmode(); //                              try { //                                  thread.sleep(5000); //                              } catch (interruptedexception e) { //                                  // todo auto-generated catch block //                                  e.printstacktrace(); //                              }                                 callreader.speak("incoming call  "                                         + contactname,                                  texttospeech.queue_add, null); //                              try { //                                  thread.sleep(5000); //                              } catch (interruptedexception e) { //                                  // todo auto-generated catch block //                                  e.printstacktrace(); //                              }                                  callreader.speak("incoming call  "                                         + contactname,                                  texttospeech.queue_add, null); 

when thread.sleep(5000)id kept in above code, text speech speak doesn't works. when thread.sleep(5000) kept commented, works successfully.

finally, want when once time speak finishs should sleep 5 s , again speak , speak again 5s sleep. why above code not working?

i assuming trying call thread.sleep() directly exposed method in service.

the methods in service synchronous. 1. hence sleep make ui wake longer 5 seconds causing anr 2. service main thread sleeping can cause anr

you should never use thread.sleep() main thread - of ui or service. spawn worker thread , thread able use tts + sleep + tts

edit 1 : added code snippet

public void foo(final object a) {     // service method     new thread() {         public void run() {         // put code here          <text speech code>         thread.sleep(5000); // work here         <text speech code>         }     }.start(); }  

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -