I’ve just developed an app for Android, it is a game but i’m not using 3D graphics. It’s a board game where i move ImageViews around on the screen. Since now I haven’t yet tested it on a mobile device, just on the emulator. The problem is that when i run my app on a Samsung Galaxy S2 phone (dual ore 🙁 ), the CPU Usage goes up to 85% and the damn phone heats up 😀 when i kill the process (close the app entirely, so it doesn’t run in the background) it goes down to 0 🙂
I don’t even know where to start fixing the problem. Could you guys give me an idea?
I can only think of two reasons for which this might happen, but they might be stupid reasons:
- With the exception of the UI thread, I have 2 more threads, each having an infinite while loop which cycles indefinite and looks if there are any messages in the message queue of each thread. Could this be the case? Should i put a delay in these loops of a couple of milliseconds, so they don’t run so fast?
- I’m also using around 20-25 imageViews on the screen which i’m moving around with via touch. Could those have anything to do with this?
Is there a way to check for memory leaks or SOMETHING … from the emulator?
If anyone can offer some advice on how i should approach this issue, i’d be grateful.
The above thing sounds suspicious to me. Instead of using infinite loop in your own thread, you should really make use of Handler which is designed exactly for this purpose.
As from developer’s site:
Besides, DDMS tab in Eclipse would give you all the required tools to investigate the excess use of CPU.