删除某些项目后,MediaStore 中的 ID 会发生什么情况?
假设:我从 SD 卡中删除了一个项目,然后卸载了存储卡。
当 Android 重新扫描我的 SD 卡以进行更改时会发生什么情况?在 MediaStore 中,每一行都有一个 _ID,因此在删除一个项目后,该 _ID 会发生什么情况:
- 它是否保留在 MediaStore 中,是否与另一个项目关联,或者,
- 它被永久删除?
Let's suppose that: I delete an item from my sd card and then, I unmount the memory card.
What happens when Android rescans my sd card for changes? In MediaStore, every row has a _ID so after I delete an item what happens to this _ID:
- Does it remain in MediaStore, it is associated with another item, or,
- It is removed permanently?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有同样的问题,找出答案的最好方法就是进行测试。
根据我所看到的,它的工作原理如下:
1)id从1开始,当媒体扫描仪添加新图像或视频时,id增加12
)如果您删除文件并且mediascanner还不知道这一点,您将尝试从 mediastore 获取,记录仍然会在那里
3) 一旦 mediascanner 发现该文件消失,它将从 mediastore 数据库中删除该记录
4) 删除的记录的 id 将不会被使用,所以如果您有三个项目ids 1,2,3 并删除项目 2 并添加一个新项目,列表将看起来像 1,3,4 - 因此删除的 ids 将不会被重用
I had the same question and the best way to find out the answer is to do the test.
based on what I saw, it works like that:
1) id is started on 1 and increments by 1 when new images or videos are added by media scanner
2) if you delete the file and mediascanner does not know about that yet and you will try to fetch from mediastore, the record still will be there
3) once mediascanner sees that file is gone, it will remove the record from mediastore db
4) the id of the removed record won't be used so if you had three items with ids 1,2,3 and drop item 2 and add a new one, the list will look like 1,3,4 - so deleted ids won't be reused