0

Here is my FileObserver code:

 private void updatecheck() {
    // Email sync loop
    mHandler.post(new Runnable() {
        @Override
        public void run() {
            if (Looper.myLooper() == null) {
                Looper.prepare();
            }

            FileObserver observerGAD7 = new FileObserver(String.valueOf(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS + "/GAD7_Client_Responses.db"))) {
                @Override
                public void onEvent(int event, String path) {
                    if ((FileObserver.MODIFY & event)!=0) {
                        System.out.println("GAD7 file event");
                        //TODO EMAIL GAD7 DATABASE AUTOMATICALLY
                    }
                }
            };
            observerGAD7.startWatching();

            FileObserver observerPHQ9 = new FileObserver(String.valueOf(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS + "/PHQ9_Client_Responses.db"))) {
                @Override
                public void onEvent(int event, String path) {
                    if ((FileObserver.MODIFY & event)!=0) {
                        System.out.println("PHQ9 file event");
                        //TODO EMAIL PHQ9 DATABASE AUTOMATICALLY
                    }
                    //   Looper.myLooper().quit();
                }
            };
            observerPHQ9.startWatching();
            Looper.loop();
        }
    });
}

It is returning 2 reports to log rather than just one. This would mean that 2 automatic emails, once implemented, would be sent which isn't ideal.

Can anyone help me with my syntax?

guipivoto
  • 18,327
  • 9
  • 60
  • 75
  • What message is printed twice? – guipivoto Jul 14 '16 at 03:05
  • 1
    That code is severely broken. It will hang the Looper associated with myHandler until the Looper spawned in the Runnable exits. I'm not sure what you are trying to do, but that makes no sense. – G. Blake Meike Jul 14 '16 at 03:57
  • Currently the code needs to continuously examine two files. If they have been modified, a copy is automatically emailed However, at present the code is just writing a comment to system log. It should only write once, not twice. – NormalUser Jul 14 '16 at 15:33

1 Answers1

-1

what is your problem? it is not clear for me to see you problem. maybe i can help you.or you can see the source code about Looper&Handler

whis
  • 1