Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
ANRs on Android platform — Gideros Forum

ANRs on Android platform

Hi everyone,

I read the following article regarding the most common issues with Android apps:

https://medium.com/googleplaydev/how-to-fix-app-quality-issues-with-android-vitals-and-improve-perfo

In particular, I found the following interesting:

What are the common reasons for ANRs?

Executing disk or network I/O on the main thread. This is by far the most common cause of ANRs. While most developers agree that you shouldn’t read or write data to disk or network on the main thread, sometimes we’re all tempted to do it. Reading a few bytes from disk will probably not cause an ANR under ideal conditions, but it’s never a good idea. What if the user has a device with slow flash memory? What if their device is under extreme pressure from other apps that are simultaneously reading and writing, while your app waits in the queue to perform your “fast” read operation? Never perform I/O on the main thread.

How is file saving / loading done under the hood in Gideros. We design educational apps / game so this is important to us as we have to save a fair amount of data.

Likes: totebo

Tagged:
+1 -1 (+1 / -0 )Share on Facebook

Comments

  • totebototebo Member
    Really good post.

    In all my games I've had issues with data disappearing or becoming corrupt, meaning the player loses all of their progress. This appears to only happen on Android (I see the issue angrily reported in one star reviews) and doesn't affect a large percent of players.

    Maybe it could be related to the I/O running on the main thread? If so, should I run all saving and loading as an Async call?
    My Gideros games: www.totebo.com
  • antixantix Member
    edited July 2018
    In a recent experiment with an ARPG system I had a lot of fun with file saving. Initially I just had all of my data in a giant table which I encoded to JSON and then saved to the device. This worked pretty well but once I had a few player characters created and large inventories of items the game blocked and I got loads of ANR issues.

    I rethought and split the large structure into a bunch of smaller ones. Each character was saved as a separate file, the shared stash was one file, and the game state also got its own file. My structures were not overly large but I began compressing the files with zlib before saving and then uncompressing them on loading again. As an anti cheating method I encrypted the data before compression as well.

    For each file to be saved I encoded the table into a JSON string, encrypted the JSON string using Gideros encryption library, compressed the encrypted string with zlib, and finally wrote the file to device. This worked amazingly fast,

    From my learning I am now always trying to keep relevant data together and not to make my data structures too large. also bear in mind that in a lot of cases you won't need to save every structure to the device, just ones that have been modified.

    If you are saving a bunch of files then make a little class that displays the name of the file being saved just before saving it. This gives the user an indication of what is going on and because you are saving a bunch of files but each saves quickly.. you can avoid ANR issues.

    Hope that goes a little way to help. Just squeak if you didn't get it or have other questions :)
    +1 -1 (+2 / -0 )Share on Facebook
  • simwhisimwhi Member
    @totebo We haven't experienced any issues with corrupted data but I can see that this could certainly happen.

    @antix I think I'm going to implement something similar to your approach. We already split saves across files.

    Many thanks for your comments and ideas.

  • totebototebo Member
    Nice ideas @antix. I do something similar, and save everything when the app exits or suspends (and in logical places like when a player completes a level). I'm wondering if I should do the saving as an Async call now, to avoid corrupt files if the saving goes wrong.
    My Gideros games: www.totebo.com
  • SinisterSoftSinisterSoft Maintainer
    Gideros doesn't have an async file open/load/save, etc set of functions. It would be handy if it did though.

    Likes: simwhi

    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
    +1 -1 (+1 / -0 )Share on Facebook
  • simwhisimwhi Member
    @SinisterSoft Nice idea. Could this be done as a plugin?
  • hgy29hgy29 Maintainer
    IIRC the whole lua processing (and thus sync file I/O) is done in another thread than UI thread on Android.
    +1 -1 (+4 / -0 )Share on Facebook
  • simwhisimwhi Member
    @hgy29 That's great to know.
Sign In or Register to comment.