开发者

Android MediaScanner finalize()

开发者 https://www.devze.com 2023-04-12 22:15 出处:网络
In Gingerbread 2.3.4, there are times that the unmounting of SDCard fails. When I checked the log, mediaserver is still accessing some files in the sdcard and even vold throw SIGKILL at mediaserver, m

In Gingerbread 2.3.4, there are times that the unmounting of SDCard fails. When I checked the log, mediaserver is still accessing some files in the sdcard and even vold throw SIGKILL at mediaserver, mediaserver will just turn into a zombie process and unmount operation would still fail.

I think the cause of failure is that the MediaScanner is still holding references to the objects which holds reference to the file in the sdcard. MediaScanner is used in MediaProvider to extract album art from a media file. However, even if the extracting album art operation is already finished, MediaScanner is still not released by the Garbage Collector. And when unmount operation is done on this state, unmount operation will surely fail. It will not fail when MediaScanner is released before unmounting the SDCard.

What I did is I added a release() function in the MediaScanner class which will be called by MediaProvider once it is done with extracting album art. Inside release() function, it will call native_finalize(). After the changes, I am able to unmount the SDCard successfully.

In the original source code of MediaScanner, the objects referenced by MediaScanner are released inside the finalize() function.

Is anyone of you experienced the same problem with mine? Is there other workaround aside开发者_StackOverflow中文版 from what I have mentioned above?

Any feedback will be greatly appreciated.

Regards,

artsylar

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号