Writing to file

robh

Member
Licensed User
Longtime User
I am attmepting to write a file to the application's internal cache.
Attach the created file to an email(with an intent) and finally delete the temporary file.
Unfortunately unless I step through the code using debugging the email fires up before the file exists and simlarly, if I step through, allowing a pause before the email intent, the email shows the attachment but after sending the attachment it does not exit on the email, presumably becasue as soon as I click Send the file is being deleted by the next line.

Any ideas how how can run these 3 lines with each completing before moving to the next?

Thanks in advance.
 

robh

Member
Licensed User
Longtime User
Hi Erel.

Thanks for the reply, that does seem to be the problem. As a test I have hardcoded a pth and the email client picks up and emails the file successfully. Due to the nature of this application, I would ideally like to write the files being created to a folder underneath the umbrella of the application but accessible by the email client. Is there a standard internal folder I can use that would be valid for any android device that you could recommend?

Thank you again.
 
Upvote 0

robh

Member
Licensed User
Longtime User
Thanks Erel, seems to work fine. Final issue is that the following fails as the email app is being called before the file has completed writing, is there any way to ensure the 3 steps below run in order, e.g. after each has completed.


B4X:
                                    ' write temp file 
                   File.WriteString(File.DirDefaultExternal & "/confirmations",(NumberFormat(Text,6,0)) & ".html",t)
                   ' send email
                   modGeneral.SendMail("[email protected]","Body Text","Test Confirmation",File.DirDefaultExternal & "/" & (NumberFormat(Text,6,0)) & ".html")
                  ' delete the temp file
                  File.Delete(File.DirDefaultExternal & "/confirmations", (NumberFormat(Text,6,0)) & ".html")
 
Last edited:
Upvote 0

robh

Member
Licensed User
Longtime User
Erel,

Thank as always for unbelievable support.
Just to confirm, I now understand about the closing of the email client raising the resume sub, however, looking at the code am I correct in thinking that after calling the intent, the rest of the code in the sub(in this case the delete file) continues to run as it's a seperate process from the intent that is then running?

Thanks
 
Upvote 0

robh

Member
Licensed User
Longtime User
Actually the problem is that you are deleting the file before it is sent.

You can delete the file in Activity_Resume which will be called after the user returns to the app.

Erel, is there a way of knowing which intent has caused the Resmue-Activity sub to fire? I've tried using Sender but this does not return anything other than 'Layout not availble' when the email client closes. Obviously with several things running there could be many reasons for the resume activity to be fired, in this case I need to know when the activity resumes after the email intent has completed. At the moment I'm setting a form level variable just before calling the email intent and then inspecting this on Activity Resume as a way of establishing the resume has started after the email intent, ideally I would like to use a cleaner solution if one does exist.

Thanks
 
Upvote 0
Top