Sign In Register

How can we help you today?

Start a new topic

Best way to save on pause on Android?


I've been trying to save my game's data on GameSparks using a LogEventRequest when the game is paused on Android (which I guess is the usual way the game is shut down by most Android players). Sadly, it seems that calling the LogEventRequest in Unity's OnApplicationPause() doesn't have enough time to actually save the data online. If the game is resumed right after it was paused, the LogEventRequest goes through and saves successfully.

Are there any best practices for saving the latest game state online when the player wants to quit the game on Android? So far, my best choice has been to save the game locally when pausing (as a sort of a cache), and uploading this local save online when the game is started the next time. But its meant to be possible that the game is played on multiple devices, this approach means the the other devices will practically never have the latest save data, since leaving the game doesn't manage to save it.

Any thoughts?

Best regards,


Hi Marko,

What sort of data are you trying to store on pause ? Unity also has an OnApplicationQuit() method but I'm not sure if you would have enough time to save the Data after that either. Can you let us know a little bit more about your game ? It might be best to set up your game so this data is only sent when a player hits a check point or completes a certain challenge such as finishing a level, some sort of trigger that will allow the data to be updated at a point when the player wouldn't be leaving the game straight away would be ideal. If a player leaves mid game you can use SetDurable to queue events and send them to a player comes back online on that device, similar to what you're doing at the moment. Another choice would be a warning when a player is quitting letting them know its been X amount of time since the last save was made, you could prompt them to save here after they have pressed pause. For players hard quitting the game they will just have to lose the data since their last save or use the Durable queue to upload the data when they come back online. Hope this helps.



Hi Liam,

Currently, I'm trying to send our whole save data in one event. It's basically a bunch of dynamic data packed into three different strings, which can be quite lengthy (since they can have hundreds of variables). The system was made as generic as possible so it could be easily used across different games and platforms. The size doesn't seem to be an issue though, since I tried making a simple test program that attempts to save a single int when the Android pause is called, but that doesn't get saved either. My guess is that the LogEventRequest call doesn't actually save the data online before the client gets the response, but the client never gets it since the app is closing down.

Because I'm sending all the data in a bunch (and it may be very difficult to change the approach at this point), I kinda wanted to avoid uploading the data online all the time. The game has quite a lot of things that should be reliably saved online, such as when you use consumable items, purchase items, play through a level etc. A lot of these can even be tied to transactions with real money depending on the situation, so need to be really careful with those. These could easily happen even dozens of times inside a single session, so I'm a bit worried about spending the data limits our players might have. I think on average our save data might be around 60 - 100 kilobytes at the moment.

I guess it does look like that saving the game when something important happens is the only way to go, though, so I suppose I'll have to look into that. Another alternative is to try to get the players to quit the game using in-game buttons/controls, so the data can be saved reliably, but I don't know if hard quitting by pressing the menu/application list buttons just isn't more common on the platform. I know I myself always quit applications using the menu button, since it's just so much more convenient...

Thanks for the help so far though! Let's see what I can think up.

Login to post a comment