Is there an example or instructions somewhere on the "right" way to handle Android interrupting an OF program?


Android (by design) interrupts programs in various situations: sleeping after inactivity, user shiftng to another application, changing the screen size or orientation, etc.

My OF apps have seemed to actually recover pretty well without doing much… but recently I noticed my app for some reason started returning from a snooze with just showing a white screen for some (?) reason.

Also I notice some of my OF apps often fail to load a random selection of my images and/or ofTrueTypeFonts on startup.

Is there a good example or documentation of “right” or proper/correct way(s) to gracefully handle these situations?

I know that adding android:screenOrientation="portrait" to the Activity section of an app project’s AndroidManifest.xml will stop Android doing the orientation change when the phone rotates.

Other than that, all I have found so far are three forum posts here:

This question about texture loss has a nice answer from @Arturo that’s the closest thing I know of to documentation about how to handle the interruption events… it says where to handle them and at a high level what to do, though a specific example of what that would really look like in finished working code would be nice. I imagine there should be code to not just call the load functions for all image and font textures (and sounds?) but also some check to make sure they actually loaded correctly and re-try for a while until they do and gather some info about the nature of the failure if they don’t, no?

This question has an answer from Arturo about how to get an Android to not go into sleep mode, which works nicely if that’s what you want, for that situation.

This other unanswered post suggests editing so that the Back button shuts down the OF app, so that Android will just re-launch it. I find this actually seems to work pretty well for a crude 1-line adjustment if it’s acceptable to re-start the app when snoozed and restarted. But of course it also means any OF Android app built with that hack will be unable to restore the position it was in when it was interrupted.