Issue
Hi,
In my app im trying to use Thread.sleep(100) to pause my thread, while its backgrounded in order to use less cpu, but it freezes when I open it back up.
I realized that onResume
is not being called when I reopen the app.
Any ideas why?
public void onPause() {
pause = true;
Log.d("mSTATE","THREADPAUSE");
}
public void onResume() {
pause = false;
running = true;
Log.d("mSTATE","THREADRESUME");
}
public void run() {
while(running){
while(pause && running){
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
while (!pause && running) {
Canvas c = null;
try {
c = sHolder.lockCanvas(null);
synchronized (sHolder) {
doDraw(c);
powerUps();
}
} finally {
if (c != null) {
sHolder.unlockCanvasAndPost(c);
}
}
}
}
Log.d("mState","EndofRun");
}
Solution
When you put your thread to sleep you are also blocking the UI thread thus leading to freezing of your application.
You need to check the Threads in Android way for the best performance.
http://developer.android.com/resources/articles/painless-threading.html
Answered By - Serdar Dogruyol
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.