Dario Kowalski Dario Kowalski - 6 months ago 10
Java Question

Android what if static final class gets unload (hide and show application)

Hello I'm working on a game for android. And I'm not shure how to handle classes if the user goes for example to the phones menu and back in to the game.

I heard if a android device needs memory, classes getting unload also static final classes.

Now for example I created the class Player as a singleton class should I reassemble the class every time the game gets shown again?

What's about static final classes is there a way to reasseble them or are they lost and the game doesn't work propperly until the game gets restarted?

Answer

I heard if a android device needs memory, classes getting unload also static final classes.

No. The process will be terminated entirely.

Now for example I created the class Player as a singleton class should I reassemble the class every time the game gets shown again?

You need to handle the case where your process will be terminated while it is in the background. You can handle this via some combination of the saved instance state Bundle and persisting data to disk that you need to be able to restore the game to its former state.

Comments