通过共享意向后删除文件意向、文件

由网友(风灵的角笛)分享简介:我试图通过Android的Intent.ACTION_SEND功能共享后删除临时文件。现在,我开始了活动的结果,在OnActivityResult,我删除该文件。不幸的是这只是如果我有一个断点调试它的工作原理,但是当我让它运行自如,并说,通过电子邮件发送文件,电子邮件没有附件。 I'm trying to delet...

我试图通过Android的Intent.ACTION_SEND功能共享后删除临时文件。现在,我开始了活动的结果,在OnActivityResult,我删除该文件。不幸的是这只是如果我有一个断点调试它的工作原理,但是当我让它运行自如,并说,通过电子邮件发送文件,电子邮件没有附件。

I'm trying to delete a temporary file after sharing it via android's Intent.ACTION_SEND feature. Right now I am starting the activity for a result and in OnActivityResult, I am deleting the file. Unfortunately this only works if I am debugging it with a breakpoint, but when I let it run freely and say, email the file, the email has no attachment.

我认为正在发生的事情是我的活动被删除文件时,它已经通过电子邮件发送了。我不明白的是为什么,不应该onActivityResult只能被称为后,其他活动结束?

I think what is happening is my activity is deleting the file before it had been emailed. What I don't get is why, shouldn't onActivityResult only be called AFTER the other activity is finished?

我也试图删除在onResume文件,但没有运气。

I have also tried deleting the file in onResume, but no luck.

有没有更好的方式来做到这一点?

Is there a better way to do this?

推荐答案

我设法得到它一起工作:

I have managed to get it to work with:

File tbd = new File(sharePath);
tbd.deleteOnExit();

这似乎删除文件活动关闭时。

This seems to delete the file when the activity closes.

阅读全文

相关推荐

最新文章