I am running a FileObserve application to detect new file creation in a folder. Below is a snippet of the onStartCommand of the service I use to start FileObserve.
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Thread Scan = new Thread() {
public void run() {
Log.i(TAG,"Started");
fileObserver = new FileObserve(Environment.getExternalStorageDirectory().getPath(),FileObserve.CREATE){
public void onEvent(int i, String s){
try {
//Modify files
} catch (Exception e) {
}
}
};
fileObserver.startWatching();
}
};
Scan.start();
return START_REDELIVER_INTENT;
}
When I run the application, for some time it runs in the background and detects any new file creation. This is validated through running services menu in settings, and also through some file modifications done by the application whenever a new file is created.
But after a while it stops running in background. Any new file created at this time does not undergo any modification. Also service not seen in listed running services menu. But sometimes it says restarting, but never starts at all.
Is it possible to solve this using some service flags? If not whats the alternative? Will sending a broadcast in OnDestroy() work?