0

Hello i am using a FileObserver of java to monitor a path, whose contents are updated by some app suppose A and my app.

Now the problem is when app A creates a file in the path, observer detects and triggers the event, then to process the file my app opens the file and do some processing but due to opening, it triggers the same event and thus infinite recursion starts. I did not find any way to tell FileObserver to not to fire event whenever a file is accessed by my application process. The code that i am using is following

observer = new FileObserver(path) {

            @Override
            public void onEvent(int event, String file)
            {
                if(file != null)
                  Process(file);
            }
        };
        observer.startWatching();
Zain Ul Abidin
  • 2,467
  • 1
  • 17
  • 29
  • Where is the `Process()` method located? Same activity? Same fragment? Same service? If this observer and the processing method is close by, you can just hold a flag to indicate that you are the one that is causing it to trigger in your `Process()` method, and just ignore it in that observer. – bigahega Feb 18 '20 at 15:28
  • Same class as of the observer – Zain Ul Abidin Feb 18 '20 at 15:29

0 Answers0