/* * (non-Javadoc) * * @see android.app.Service#onDestroy() */ @Override public void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); Log.e("Service Info", "Service Destoried."); if (Observer != null) Observer.stopWatching(); Observer = null; }
/* * (non-Javadoc) * * @see android.app.Service#onCreate() */ @Override public void onCreate() { // TODO Auto-generated method stub super.onCreate(); Log.e("Service Info", "Service Created."); /** 服务开启时,首先将此时此刻SD根目录下的所有文件夹信息放入SD_Files中 */ SD_Files = new HashSet(); File sd = new File(ROOTPATH); File[] files = sd.listFiles(); for (File f : files) SD_Files.add(f.getName()); /** 在此处进行Service需要执行的操作,监听SDcard中的文件夹创建情况 */ Observer = new SD_Observer(ROOTPATH); Observer.startWatching(); }