I have implemented a file observer on a folder observing for the create & delete as follows:
private FileObserver getFileObserverListener(String filepath, String fileType) {
return new FileObserver(filepath) {
@Override
public void onEvent(int i, @Nullable String s) {
if ((FileObserver.CREATE & i) != 0 || (FileObserver.DELETE & i) != 0) {
refreshFolderData(filepath, fileType);
}
}
};
}
But when I am creating/deleting multiple files in a single batch, the file observer is triggered for every single delete/create operation. Is there a way to avoid this? More specifically, is there a way to trigger the file observer exactly once for a batch of create/delete operations in a particular folder?