2

I am developing android application with Fragment,now i want to run FileObserver in background when fragment is paused. My Code:

FileObserver observer = new FileObserver(android.os.Environment.getExternalStorageDirectory().toString() + "/MyApp/") {

@Override
public void onEvent(int event, String file) {
    if(event == FileObserver.CREATE){
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.detach(MyActivity.this).attach(MyActivity.this).commit();
    }

}
};
@Override
public void onPause() {
    super.onPause();
    observer.startWatching();
}

The above code is not refreshing fragment when a new file is arrived(When the application is paused).How to archive it?

0 Answers0