I'm using Libgdx for my android game. The game runs fine, but it will automatically pause while running if there is no interaction from the user. How can I avoid the game pause?
My main class impelments AndroidApplication and my game class implements ApplicationListener.
While JRowan's answer is good for general Android applications, and can be used with Libgdx, you can also use the Libgdx support for acquiring the wakelock. See useWakelock in AndroidApplicationConfiguration. Libgdx will keep track of the wakelock for you. You still need the appropriate permissions in your manifest, though.
Specifically, in your class that extends AndroidApplication:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
cfg.useWakelock = true;
initialize(new MyGdxGame(), cfg);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With