i have such class
class c { mainactivity mainactivity; boolean ispaused; public void a() { b b = new b() { public void run() { isdone = true; } }; mainactivity.runonuithread(b); while(!b.isdone && !ispaused) { try { thread.sleep(1); } catch(exception e) { e.printstacktrace(); break; } } } } abstract class b implements runnable { public boolean isdone = false; } then called in renderer implements glsurfaceview.renderer
@override public void ondrawframe(gl10 gl) { c.a(); } c instanceof c and, mainactivity call glsurfaceview.onpause , onresume when onpause , onresume of called. set ispaused of c. glsurfaceview's onpause , onresume call super's onpause , onresume.
then when onpause , onresume called, app freezed. find problem, removed other code except explained, still occurs. how can fix it?
ondrawframe being executed on ui thread. blocking thread indefinitely because never going have !b.isdone && !ispaused evaluate false. should never call thread.sleep() on main ui thread.
edit: wrong this. renderer called separate thread prevent such block on ui thread. however, there still issue sharing variable (isdone) between 2 threads. can overcome making isdone volatile.
Comments
Post a Comment