android - How to prevent Thread.Sleep in onDraw affecting other Activities? -



android - How to prevent Thread.Sleep in onDraw affecting other Activities? -

i have custom view class drawing images. problem when utilize thread.sleep(200); in ondraw method, affects xml elements in same activity. have wait 200 miliseconds untill happens.

mainpage extends activity implements onclicklistener{ oncreate(...){ relativelayout rl = (relativelayout) findviewbyid(r.id.main_rl); rl.addview(new customview(this)); } onclick(view v){ switch(v.getid){ ... }; } } customview extends view{ ondraw(){ try{ thread.sleep(200); .... } } }

any help appreciated.

never run long operations in ui listener callback (or anywhere else runs on ui thread) in android. instead, create new thread perform sleep , whatever needs done. remember if want interact ui again, need within ui thread, can schedule calling runonuithread().

customview extends view{ ondraw(){ (new thread(myrunnable)).start(); } } runnable myrunnable = new runnable() { void run() { seek { thread.sleep(...); } catch...; do_non_ui_things_if_needed(); runonuithread(some_runnable_for_this_if_needed); } }

android multithreading ondraw thread-sleep

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -