Search code examples
javaandroidlibgdxresume

Why does LibGDX's resume() method not get called on my Android devices?


I have multiple devices that run Android OSes. I've been building a LibGDX game, and have been having a problem with it where, every time the user pressed the home button and then proceeds to reenter the app, the app restarts. I don't want this. I've been talking to a lot of people lately trying to figure out why my resume() method doesn't run on my devices. This is the method which would help me reload my data/assets and keep the game it was before the user exited.

So tell me: Why do my devices not run this pause() method, but a lot of other people's devices DO?

For the record: My two devices that I test on are a Galaxy S4 phone and a Nexus 7 tablet.


Solution

  • You do not have any control over how the Android system manages the lifetime of your application when its not in the foreground. As such you need to deal with all the possible transitions. The device is free to terminate your app when it is backgrounded (especially if its using a relatively large amount of resources).

    In Libgdx the resume method is only invoked on an actual resume from suspend (i.e., long-press home to switch to a different app and then long-press home to switch back). Other frameworks (including bare Android) often invoke resume on first-start, so that may be a source of confusion. (Just put the first-start work in your create callback.)

    For some more details on the lifecycle of Libgdx Android apps and how to recreate the various cases, check out: http://bitiotic.com/blog/2013/05/23/libgdx-and-android-application-lifecycle/