Android Switching Activities Black Screen -


i'm trying start activity in main activity using method:

 public void switchtoread(){// switches reading view displays text tts engine reads off.     intent intent = new intent(getapplicationcontext(),readout.class);     intent.putextra("response", res);     startactivity(intent); } 

this starts following class:

package com.example.webview;  import android.os.bundle; import android.app.activity; import android.app.progressdialog; import android.content.context; import android.content.dialoginterface; import android.content.dialoginterface.onclicklistener; import android.content.intent; import android.speech.tts.texttospeech; import android.text.method.scrollingmovementmethod; import android.view.menu; import android.view.view; import android.widget.button; import android.widget.textview;  public class readout extends activity implements texttospeech.oninitlistener, onclicklistener {       boolean paused = false;     string lefttoread = null;     string res = null;     texttospeech tts;      protected void onpreexecute()     {           system.out.println("pre-execute");      }       @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.read_out);         intent intent = getintent();         res = intent.getextras().getstring("response");         textview textv = (textview) findviewbyid(r.id.textview1);         textv.settext(res);         textv.setmovementmethod(new scrollingmovementmethod());         android.view.display display = ((android.view.windowmanager)getsystemservice(context.window_service)).getdefaultdisplay();          textv.setheight((int)(display.getheight()*0.76));         system.out.println("start");         tts = new texttospeech(this, this);     }      @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         return true;     }      public string speakfull(string text){         system.out.println("speaking: " + text);         system.out.println("speaking");         string[] sentences = text.split("\n|\\.(?!\\d)|(?<!\\d)\\."); // regex splits body of text sentences of body stored in string array.         for(int = 0; < sentences.length; i++){             if(!tts.isspeaking() && !paused){                 system.out.println("speaking: " + i);                 tts.speak(sentences[i], texttospeech.queue_flush, null);             }else if(paused){                 system.out.println("paused");                 string paused = "";                 int k = 0;                 if(i != 0){                     k = i-1;                 }                 lefttoread = null;                 for(int j = k; j < sentences.length; j++){                     lefttoread += sentences[j];                 }                 return lefttoread;             }else{                 i--;                 system.out.println("sleeping");                 system.out.println("speaking : " + tts.isspeaking());                 try {                     thread.sleep(1000);                 } catch(interruptedexception ex) {                     thread.currentthread().interrupt();                 }             }             if(i == sentences.length - 1){                 return "message 001: complete";             }         }         return null;     }      @override     public void oninit(int arg0) {             system.out.println("speakfull");             lefttoread = speakfull(res);      }      public void clickpause(view v){         if(paused){             paused = false;             button b = (button) findviewbyid(r.id.button1);             b.settext("play");         }else{             paused = true;             button b = (button) findviewbyid(r.id.button1);             b.settext("pause");             if(lefttoread == null){                 lefttoread = speakfull(res);             }else{                 lefttoread = speakfull(lefttoread);             }         }     }      @override     public void onclick(dialoginterface arg0, int arg1) {         // todo auto-generated method stub      }  } 

after readout class started 1 of couple things can happen, either screen turns black, text speech begins reading, , app telling me it's not responding, or shows me view readout, reads in text speech, , tells me it's not responding. i'm confused why happening, , insight appreciated.

i don't know using tts can tell line causing problem

 thread.sleep(1000); 

it appears calling on ui thread isn't idea. need use background thread , update runonuithread() or asynctask or use handler.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -