How to copy files before user delete them - Android
<p>i'm a newbie. I'm making an application that works as an Recycle Bin. And i have a problem need help.</p>

<ul>
<li>I use android File Observer methods then i am getting notified after file deletion, then i copy it with path into my folder. <strong>But new file in folder is empty</strong>.</li>
</ul>

<p>This is my code File Observer: </p>

<pre><code>public void startWatching() {
    if (mObservers != null) return;

    mObservers = new ArrayList&lt;SingleFileObserver&gt;();
    Stack&lt;String&gt; stack = new Stack&lt;String&gt;();
    stack.push(mPath);

    while (!stack.isEmpty()) {
        String parent = stack.pop();
        mObservers.add(new SingleFileObserver(parent, mMask));
        File path = new File(parent);
        File[] files = path.listFiles();
        if (null == files) continue;
        for (File f : files)
        {
            if (f.isDirectory() &amp;&amp; !f.getName().equals(".") &amp;&amp; !f.getName().equals("..")) {
                stack.push(f.getPath());
            }
        }
    }

    for (SingleFileObserver sfo : mObservers) {
        sfo.startWatching();
    }
}

@Override
public void stopWatching() {
    if (mObservers == null) return;

    for (SingleFileObserver sfo : mObservers) {
        sfo.stopWatching();
    }
    mObservers.clear();
    mObservers = null;
}

@Override
public void onEvent(int event, String path) {
    switch (event)
    {
        case FileObserver.ACCESS:
            Log.d("RecursiveFileObserver", "ACCESS: " + path);
            break;
        case FileObserver.ATTRIB:
            Log.i("RecursiveFileObserver", "ATTRIB: " + path);
            break;
        case FileObserver.CLOSE_NOWRITE:
            Log.i("RecursiveFileObserver", "CLOSE_NOWRITE: " + path);
            break;
        case FileObserver.CLOSE_WRITE:
            Log.i("RecursiveFileObserver", "CLOSE_WRITE: " + path);
            break;
        case FileObserver.CREATE:
            Log.i("RecursiveFileObserver", "CREATE: " + path);
            break;
        case FileObserver.DELETE:
            Log.e("Save:", "Save file user delete");

            File dir = new File(Environment.getExternalStorageDirectory() + File.separator + ConstantUtils.FOLDER_RESTORE);
            if (!dir.exists()){
                dir.mkdir();

            }
            File inputFile = new File(path);
            String  str = String.valueOf(inputFile);
            if (!str.isEmpty()){
                String [] result =  str.split("/");
                int i = result.length;
                if (i &gt; 4) {
                    String inputPath = result[i - 1];
                    File outputFile = new File(Environment.getExternalStorageDirectory() + File.separator + ConstantUtils.FOLDER_RESTORE + File.separator + inputPath);
                    String str1 = String.valueOf(inputFile);
                    String str2 = String.valueOf(outputFile);
                    if (str1.compareTo(str2) != 0){
                        ZipHelper.copyFileToFolder(inputFile, outputFile);
                    }
                }
            }
            break;
        case FileObserver.DELETE_SELF:
            Log.i("RecursiveFileObserver", "DELETE_SELF: " + path);
            break;
        case FileObserver.MODIFY:
            Log.i("RecursiveFileObserver", "MODIFY: " + path);
            break;
        case FileObserver.MOVE_SELF:
            Log.i("RecursiveFileObserver", "MOVE_SELF: " + path);
            break;
        case FileObserver.MOVED_FROM:
            Log.i("RecursiveFileObserver", "MOVED_FROM: " + path);
            break;
        case FileObserver.MOVED_TO:
            Log.i("RecursiveFileObserver", "MOVED_TO: " + path);
            break;
        case FileObserver.OPEN:
            Log.i("RecursiveFileObserver", "OPEN: " + path);
            break;
        default:
            Log.i("RecursiveFileObserver", "DEFAULT(" + event + "): " + path);
            break;
    }
}
</code></pre>

<p>Please tell me how can i do it. Sorry for my English not good. Many thanks!</p>