通过共享意向后删除文件 [英] Delete file after sharing via intent

查看:125
本文介绍了通过共享意向后删除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过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.

这篇关于通过共享意向后删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆