Android110408: FileObserver注记
Email: zcatt@163.com
Blog http://zcatt.blog.chinaunix.net
内容提要
FileObserver.以供备忘和参考。
声明
仅限学习交流,禁止商业用途。转载需注明出处。
版本记录
Date Ver Note
2011-04-08 0.1 Draft. zcatt, Beijing
借助FileObserver可以得到访问文件/目录时的各种事件. 派生FileObserver子类必须实现onEvent()方法. 通常的调用过程.
YourFileObserver observer = new YourFileObserver(path, eventMask);
... ...
observer.startWatching()
... ...
// your proc
... ...
observer.stopWatching()
有一点要特别注意, FileObserver有自己的特别线程, onEvent就运行在这个线程中, 因此要注意同步问题, 并且不要在onEvent()中执行太耗时的操作. 可以考虑使用Handler机制.
阅读(920) | 评论(0) | 转发(0) |