I have a Galaxy S4 Mini.
I am developing my unity app.
I build the app and run it on my phone.
Every time I try to play right after building I have lag spikes every seconds. The game runs smoothly, I would say 40-50 fps.
I run the app after 1 minute, I cleared cache, ram, data. And still I get lag spikes.
I stop the app and clear cache and data and ram. I wait say about 30 minutes and try running the app again, and BAM it runs smoothly with no lag spikes.
I hope someone has an answer to this question. I am also running into a similar issue.
I have three devices, on one of those (Huawei P7) it has large lag spikes every seconds. I can clear cache and data, but this does not seem to help. Then in some strange way after waiting a while it runs perfectly.
One thing I observed is that it starts at the unity splash screen. So the issue is there from the start of the application.
note: On the other devices I do not have this issue, so you would think it is an issue with my Huawei P7. But other games run just fine on the device.
I hope someone can help us out
You Android phone has a lot going on. You can make the best performing app in the world and if Android OS wants the resources, your game is getting throttled. No two ways about it.
Follow instructions to get the profiler running for your Android build or use LogCat to see whats going on. The chances are you are using something which presents a struggle for lower-end devices which doesnt show as a problem on others. Different hardware shows different characteristics.
This link could be outdated but you get the idea
I think the Splash screen runs simulaneously to the Start methods of the first existing gameobjects (could be awake). Check your start and awake methods for coroutines that may continue through the whole game or situations in which multiple coroutines may run. Lag spikes also can occur from large amounts of regular GameObject Instantiation and Destruction; Garbage Collection will put eveything on hold until it has run.
Thanks for the the answer but I figured it out.
My phone has Android Version 4.4.4 and I tried my game on 5 different phone with Version 5.0 and above and it worked just fine. So I am 100% sure it is the phone.