I'm new in Android and I'm trying to write a simple game. This is the Main Thread game loop (very simple) that I use (I don't know if is this the problem):
@Override
public void run(){
[...]
while(running) {
startTime = System.nanoTime();
canvas = null;
//try locking the canvas for pixel editing
//update and draw GameObjects
[...]
timeMillis = (System.nanoTime() - startTime) / 1000000;
waitTime = targetTime-timeMillis;
try{
this.sleep(waitTime);
}catch(Exception e){}
totalTime += System.nanoTime()-startTime;
frameCount++;
if(frameCount == FPS){
averageFPS = 1000/((totalTime/frameCount)/1000000);
frameCount =0;
totalTime = 0;
System.out.println(averageFPS); //Testing
}
}
Now... The project use Android 4 API and I'm testing this game on OnePlus 5. When I upgrade my phone to Android 8, the FPS number has dropped dramatically. With Android 6 I can reach 62 FPS, now (with the SAME code) I can not exceed 13 FPS! Why? The problem is in my project or in Android? Can I fix it?