Android Application Suspend/Resume for Snapshot.

I’m using Snapshots mainly for this feature that’s discussed in the Snapshot Tutorial… “Better yet, if you create a snapshot and don’t need to re-render or update its contents later, you can remove the objects that were used to create the snapshot and free up the related texture memory.

In other words, I would like to delete the objects added to the snapshot as soon as possible (after inserting them to the canvas) to free up memory usage while they remain in the snapshot image.

The only problem is what am I supposed to do regarding this Gotcha? “When an app is suspended, the Android OS removes all OpenGL textures from memory. When the app is resumed, Corona must reload all images, but the capture image no longer exists in memory. If you need to restore a snapshot image in Android, one solution is to save the returned capture image to file via the display.save() function. Note that this should be done immediately, not during the “applicationSuspend” or “applicationExit” system events (at those times, there will be no OpenGL textures in memory to save).

Assuming I didn’t delete the children, then I could just invalidate. But since I deleted them, does this mean I have to say store all the positional/rotational data, recreate all these objects from scratch, and then re-add them to the snapshot? Alternatively, if I cannot use display.save() upon applicationSuspend or applicationExit, then it’s likely pretty useless to me in cases where I’m constantly updating the snapshot and would like the latest update to be saved in case the app suspends… in which case I would have to constantly be calling display.save(), correct?

Are those my only options? Or are there any other alternative?

Not a fan of snapshots but off the top of my head I would just save the snapshot to the cache directory and then just reload using newImage from appresume.

Thank you for your response @Christopher Bishop. Unfortunately, I’m seeking a bit deeper of an understanding regarding the handling of this snapshot issue.

I understand that saving is an option (assuming you’re talking about display.save()). But, when am I supposed to save it? If I understand the gotcha above, it means that I cannot save during applicationSuspend or applicationExit? Well, assuming a user may suspend the app, does this mean that I’d have to constantly be saving the snapshot image? Like for instance upon every addition of a child, I would save a new version of the snapshot to ensure the latest version is saved in case of app suspension? If so, assuming I’m constantly adding new children very quickly in certain circumstances, then this could drastically effect performance negatively, correct? (because I would being saving quite often)

Is my only other alternative to keep a running log of positional/rotational data of all the children being added and removed from the snapshot? Then if the app gets suspended and resumed, I’d recreate and re-add them to the snapshot upon application resume? Would this really save me that much in regards to memory and performance compared to if I just had a display group, with all the children never deleted? 

Lastly, is anything ever going to be done about this Android suspension issue? I was very excited to use snapshots for the reason discussed in my first posting. But this issue seems to be way too inconvenient for me to use snapshots solely for that purpose. Am I understanding this correctly?

Hi @jhow,

Can you outline the scenario when you’d be adding many, many children in quick/immediate succession to the snapshot? Would this occur in a loop? Via some user touch “moved” detection over a fast succession of touch positions? I may be able to advise you better if I understand how your actual scenario will work.

As for the Android OpenGL “dump” on suspend, there is really nothing we can do about this. It’s how Android works and we are susceptible to the boundaries set by each OS.

Brent

Hey @Brent Sorrentino,

An example would be if I were sprinkling many sprinkles on a cake by dragging my finger over the cake. Each time a sprinkle lands, I would want to add it to my snapshot, then invalidate the snapshot. But then I would have to save it to file afterwards (in fear that the user might sometimes suspend the app). If I always wanted the most updated cake with sprinkles image, I would have to save an image after every individual sprinkle.

Anyways, I ended up just removing Snapshots. Unfortunately, the benefits of using it to remove display objects wasn’t worth the amount of effort to try to solve an issue like this. Thanks anyways for your time. Greatly appreciated.

Not a fan of snapshots but off the top of my head I would just save the snapshot to the cache directory and then just reload using newImage from appresume.

Thank you for your response @Christopher Bishop. Unfortunately, I’m seeking a bit deeper of an understanding regarding the handling of this snapshot issue.

I understand that saving is an option (assuming you’re talking about display.save()). But, when am I supposed to save it? If I understand the gotcha above, it means that I cannot save during applicationSuspend or applicationExit? Well, assuming a user may suspend the app, does this mean that I’d have to constantly be saving the snapshot image? Like for instance upon every addition of a child, I would save a new version of the snapshot to ensure the latest version is saved in case of app suspension? If so, assuming I’m constantly adding new children very quickly in certain circumstances, then this could drastically effect performance negatively, correct? (because I would being saving quite often)

Is my only other alternative to keep a running log of positional/rotational data of all the children being added and removed from the snapshot? Then if the app gets suspended and resumed, I’d recreate and re-add them to the snapshot upon application resume? Would this really save me that much in regards to memory and performance compared to if I just had a display group, with all the children never deleted? 

Lastly, is anything ever going to be done about this Android suspension issue? I was very excited to use snapshots for the reason discussed in my first posting. But this issue seems to be way too inconvenient for me to use snapshots solely for that purpose. Am I understanding this correctly?

Hi @jhow,

Can you outline the scenario when you’d be adding many, many children in quick/immediate succession to the snapshot? Would this occur in a loop? Via some user touch “moved” detection over a fast succession of touch positions? I may be able to advise you better if I understand how your actual scenario will work.

As for the Android OpenGL “dump” on suspend, there is really nothing we can do about this. It’s how Android works and we are susceptible to the boundaries set by each OS.

Brent

Hey @Brent Sorrentino,

An example would be if I were sprinkling many sprinkles on a cake by dragging my finger over the cake. Each time a sprinkle lands, I would want to add it to my snapshot, then invalidate the snapshot. But then I would have to save it to file afterwards (in fear that the user might sometimes suspend the app). If I always wanted the most updated cake with sprinkles image, I would have to save an image after every individual sprinkle.

Anyways, I ended up just removing Snapshots. Unfortunately, the benefits of using it to remove display objects wasn’t worth the amount of effort to try to solve an issue like this. Thanks anyways for your time. Greatly appreciated.