Android App High Cpu-usage
Solution 1:
You can try divide the operation into smaller pieces and place Thread.sleep()
for a short time. If that's not enough try changing some code into loop like this:
Old code:
object.move(1000);
New code:
for (int i=0; i<100; i++) {
object.move(10);
Thread.sleep(10);
}
If the example move()
operation takes more time if the given parameter is higher, the old code can cause your program non-responding. The new code will allow android to comunicate with your program during Thread.sleep()
, so your app shoud not stop working.
@edit As I can see in your code - you do have several while loops. Try placing Thread.sleep(10) inside them.
Solution 2:
You're putting this code directly in a Service which runs on the main thread. You need to instead put it in a background thread. Consider using an IntentService
instead or start a worker thread from your service.
Post a Comment for "Android App High Cpu-usage"