gaurav jain
gaurav jain

Reputation: 3234

FileObserver is only called once

I have 1 fileObserver declared in the onCreate function of an activity. For the first time, whenever you do any change to the file directory (to be specific I delete the folder), observer works and broadcasts an intent. But from the second time onwards, observer stops working, and no intent is broadcasted. If I move the observer to onResume of the activity, it works like a charm. But as per the concept, fileobserver should continuously work in the background once it is started. I do not call stopWatching() at any place. Any help would be appreciated.

Upvotes: 1

Views: 1589

Answers (1)

1615903
1615903

Reputation: 34909

For the first time, whenever you do any change to the file directory (to be specific I delete the folder)

On DELETE_SELF event the FileObserver stops itself and no new events occur, even if you create a folder with the same name later on. If you want to continue monitoring when the folder is recreated, you need to create a new FileObserver.

Upvotes: 2

Related Questions