Do something on app close?

Is there a way to trigger a final procedure as an app exits?

One of my apps generates user input via image picker, and while I know it only stores 10 selections it still adds clutter to gallery. I would like to delete the picked images through taifun file on app close.

I know how to delete stuff, just not quite sure how to utilize closing the app to trigger the procedure.

When you click close app, you first call the delete routine, then close the app.

Something like this:


Maybe it will work without a timer. But I wouldn't be so sure on slow (old) devices (especially not if many files / large images are to be deleted).

The problem in my specific case is this is more of a PWA, it uses webview on a specific site, there are no buttons to trigger the event. Uploads are permitted which is what image picker is used for and unfortunately there is no "on upload complete" block that I could use either.

Anke gave me an idea though. I use the back button to "go back" to the starting website. I could probably include an if then statement like if current url = starting url on back press, then call taifun filelist and for each item in the file list call taifun delete. Then close.

Marking you as the solution as you gave me an idea above that will probably work. Also the timer part is a good tip.

See any glaring issues here?Screenshot 2021-06-10 7.51.19 PM

Hmm, not deleting the files. Screenshot 2021-06-10 10.57.51 PM

As I said, use a timer.

No idea what was going on before, I removed the "close application" to test the delete to ensure it wasn't a race condition and it still wasn't working. It had to either be something to do with the path, or some nuance with the delete block since this is essentially the same thing I had before, just more roundabout.

I ended up using the attached in the delete procedure, which does work. Get file list > Remove file path (except filename) and rewrite to list > Get revised list > Call delete for each item and add back in the file path.

Will add in close later.

Screenshot 2021-06-11 9.45.10 AM

If you are testing with the compiled app (APK), you must ask for WRITE permission.
Where do the images come from? grafik

Try this:

or this:

Ummm WAT?

My compiled apk works fine with what I posted above....Not sure what you are suggesting, as the issue with my other attempts can be narrowed down to either a block issue or filepath issue. Given the working solution only strips the path and reintroduces it later....and works.

Your first "Try this" is the exact thing I already posted..and said didn't work. Even though it should.

The native image picker in ai2 copies the selected image when called/selected to /Pictures/_app_inventor_image_picker/
its literally in the ai2 docs. I hate it.

Of course you don't see read/write permission. I grant it on screen initialize which obviously I didnt post because it isn't relevant. My total blocks are huge. If you haven't gathered, I do ok in ai2.

Yes I could have used async, but this job isn't that big.

Show the corresponding blocks.

For me it works fine (to remove 5-10 images).

Show the corresponding blocks's an inherent property of image picker.

Here is the literal documentation on it. Try it yourself.

A special-purpose button. When the user taps an ImagePicker , the device’s image gallery appears, and the user can choose an image. After an image is picked, it is saved, and the Selection property will be the name of the file where the image is stored. In order to not fill up storage, a maximum of 10 images will be stored. Picking more images will delete previous images, in order from oldest to newest.

The location image picker saves selections is /Pictures/_app_inventor_image_picker/

Ok, which Android version?


This picture shows exactly what I and the documentation have both said... Not sure why you are still doubting....

It stores 10 images before overwriting the earliest. This is an issue because it shows up in the users gallery.

No, and you didn't say that, nor can it be found in the documentation.

I don't doubt, I'm just saying that it works for me.

And why you need to do this to remove the files will probably remain your secret.
I have no problems with that at all.

No, look at your blocks:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.