Slowing The Gui Down In Android
Solution 1:
You're not seeing the score because sleeping on the UI thread prevents the layout and drawing operations that make your text changes visible. Never sleep on the UI thread.
Using a new thread for this is overkill. Use a Handler and the postDelayed method to make something happen after a delay.
privatefinalHandlermHandler=newHandler();
Then when you want to do something later,
mHandler.postDelayed(new Runnable() {
publicvoidrun() {
doDelayedThing();
}
}, 3000);
Solution 2:
As others have pointed out: don't use sleep
in the UI thread.
What you should do instead is described here:
http://developer.android.com/guide/appendix/faq/commontasks.html#threading
in section "Handling Expensive Operations in the UI Thread"
Solution 3:
It is not recommended to ever sleep the main UI thread. Try something like this:
new Thread(new Runnable(){ //do work here });
Or you could try using a Toast popup for the score.
Solution 4:
You can also use Timer to wait 3 seconds, which will start a new thread after the time runs out.
Timertimer=newTimer();
timer.schedule(newTimerTask() {
@Overridepublicvoidrun() {
AnViewanimator=newAnView(this);
layout.addView(animator);
}
}, 3000);
Post a Comment for "Slowing The Gui Down In Android"