snapshot goes away when app is sleep then awake

In my snapshot, whenever my phone goes to sleep, and I awake it, all the items in a snapshot is gone.

How to resolve this?

here is my code for snapshot :

for i = 1,#weekdays do snapWeekDays[i] = display.newSnapshot(90,90) end

this is how I populate it with a rectangle and a text

for i = 1, #weekdays do local box = display.newRect(0,0, 45,45) box:setFillColor(0.043, 0.360, 0.043) box.anchorX = 0 box.anchorY = 0 snapWeekDays[i].group:insert(box) local text = display.newText( { parent = snapWeekDays[i].group, text = weekdays[i].abv, font = native.font, y = 10, height = 20, width = 30, x = 10, align="center", fontSize = 20 }) text.anchorX = 0 text.anchorY = 0 snapWeekDays[i].x = currentX snapWeekDays[i].y = 150 -- snapWeekDays[i].y = currentY print("currentX "..currentY) currentY = currentY + 46 currentX = currentX + 46 sceneGroup:insert(snapWeekDays[i]) end

it goes well when my app  goes to this part and my phone goes to sleep and i awake it, the snapshot is gone totally,

Hi @vonncc123,

I assume you’re testing for Android? If so, this is somewhat a limitation of Android… when an app is suspended, the Android OS removes all OpenGL textures from memory, and so when the app is resumed, the snapshot capture image no longer exists in memory (Corona must reload them). If you need to restore a snapshot image in Android, you might try saving the snapshot image to an image using “display.save()”, then fetching that image back on resume.

Brent

Wow okay thanks hehehe  :)), Yes im using Android, so in iOS this bug will not trigger?  btw additional question, can I use the “display.save()” on a BLOB data type? my database has a reference in a web server, where my web server can save Images, and its data Type is BLOB, and I connect using JSON then save the JSON decoded table to sqlite database

display.save() is going to output either a JPEG or PNG (depending on the file extension you provide) and it will write it out to your system.DocumentsDirectory (or other writable directory you specify).  From there you could use the File IO routines to open and read the binary data an put that inside a blog field in you database.  How you encode the blob to talk to your server is up to you.  We really can’t help with that.

Rob

Oh okay,  btw, once the OpenGL is disabled can the snapshot or a rectangle in it, still detect touch listeners?

Hi @vonncc123,

I’m not quite sure what you mean… the snapshot is discarded from memory (on Android) when the app is suspended, but when it resumes, and you reload the saved texture or re-create it as a snapshot, you can put touch listeners back on that object as normal. Perhaps I don’t understand what you’re asking…

Best regards,

Brent

You can also save the handles to the snapshots into a table and then have something like this in your code:

if (isAndroid) then local onSystemEvent = function(event) local eventType = event.type if (eventType == "applicationResume") then for i = 1, #snapshotTable do if (type(snapshotTable[i].invalidate) == "function") then snapshotTable[i]:invalidate() end end end end Runtime:addEventListener("system", onSystemEvent) end

Hi @vonncc123,

I assume you’re testing for Android? If so, this is somewhat a limitation of Android… when an app is suspended, the Android OS removes all OpenGL textures from memory, and so when the app is resumed, the snapshot capture image no longer exists in memory (Corona must reload them). If you need to restore a snapshot image in Android, you might try saving the snapshot image to an image using “display.save()”, then fetching that image back on resume.

Brent

Wow okay thanks hehehe  :)), Yes im using Android, so in iOS this bug will not trigger?  btw additional question, can I use the “display.save()” on a BLOB data type? my database has a reference in a web server, where my web server can save Images, and its data Type is BLOB, and I connect using JSON then save the JSON decoded table to sqlite database

display.save() is going to output either a JPEG or PNG (depending on the file extension you provide) and it will write it out to your system.DocumentsDirectory (or other writable directory you specify).  From there you could use the File IO routines to open and read the binary data an put that inside a blog field in you database.  How you encode the blob to talk to your server is up to you.  We really can’t help with that.

Rob

Oh okay,  btw, once the OpenGL is disabled can the snapshot or a rectangle in it, still detect touch listeners?

Hi @vonncc123,

I’m not quite sure what you mean… the snapshot is discarded from memory (on Android) when the app is suspended, but when it resumes, and you reload the saved texture or re-create it as a snapshot, you can put touch listeners back on that object as normal. Perhaps I don’t understand what you’re asking…

Best regards,

Brent

You can also save the handles to the snapshots into a table and then have something like this in your code:

if (isAndroid) then local onSystemEvent = function(event) local eventType = event.type if (eventType == "applicationResume") then for i = 1, #snapshotTable do if (type(snapshotTable[i].invalidate) == "function") then snapshotTable[i]:invalidate() end end end end Runtime:addEventListener("system", onSystemEvent) end