将文件从一个位置复制到另一个位置
我正在将文件从 SD 卡中的一个位置复制到另一个位置。 现在,在复制开始时,我使用进度对话框,但是我如何知道我的文件已传输以关闭进度对话框。我无法关闭进度栏,因为我不知道如何获取传输消息完全的。 请帮我出去..
I am copying file from one location to another location in sdcard.
now at the time when copy starts i use a progress Dialog,but how can i know that my file has been transferred to close the progress dialog.I am not able to close progress Bar because I don't know how to get message of transfer complete.
Please help me Out..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看看这篇最近的帖子和弗拉基米尔的回答,我认为服务可能有点矫枉过正(取决于您的具体情况)。 AsyncTask 可能是正确的选择。
想要在Activity的onCreate中显示AlertDialog - android
Have a look at this very recent post and Vladimir's answer, I think a Service may be overkill (depending on your exact situation). AsyncTask would probably be the way to go.
Want to display AlertDialog in onCreate of Activity - android
启动将文件复制到 SD 卡的服务。我推荐 IntentService,因为它会自动为您创建一个单独的线程。文件复制完成后,从您的服务发送包含您意图的广播。然后回到您的活动类中创建一个将处理广播的广播接收器。不要忘记将您的服务包含在 androidmanifest.xml 文件中。这是一些代码:
此代码将在您的服务结束时
如果文件复制失败,请执行此操作
然后回到您的主活动类,您必须收到意图:
此外,在您的活动中,您必须注册/取消注册广播
Start a service that will copy the file to the sd card. I recommend IntentService because it automatically creates a separate thread for you. Once the file is done being copied send a Broadcast from your service with your intent. Then back in your activity class create a Broadcast Receiver that will handle the broadcast. Don't forget to include your service in the androidmanifest.xml file. Here is some code:
This code will go at the end of your service
If the file failed to copy do this
Then back in your main activity class you must receive the intent:
Also in your activity you must register/unregister the broadcast