android - Why does the ui not load till the while loop ends? -


even though while loop in thread, ui not load till while break condition. want ui load inspite of infinite while loop running. how handle such situation ?

public class mainactivity extends appcompatactivity { protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     /* runonuithread th=new runonuithread(new textchange());*/     new thread() {         public void run() {             try {                 runonuithread(new runnable() {                      @override                     public void run() {                         runonuithread(new runnable() {                             @override                             public void run() {                                 // change ui elements here                                 textview tv = (textview) findviewbyid(r.id.tv);                                 while (true) {                                     int y = 10;                                 }                             }                         });                     }                 });                 thread.sleep(30);             } catch (interruptedexception e) {                 e.printstacktrace();             }         }     }.start(); } @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.menu_main, menu);     return true; } @override public boolean onoptionsitemselected(menuitem item) {     // handle action bar item clicks here. action bar     // automatically handle clicks on home/up button, long     // specify parent activity in androidmanifest.xml.     int id = item.getitemid();      //noinspection simplifiableifstatement     if (id == r.id.action_settings) {         return true;     }     return super.onoptionsitemselected(item); } } 

first of runonuithread doesn't have effect of code inside oncreate method runs on ui thread design, means don't have put inside separate runonuithread block. secondly, you'll have use asynctask to create new background thread more optimized small background stuff , interact main ui thread. , third, you're creating infinite loop means won't come out of it. check out.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -