title: window.requestFileSystem fails/events firing multiple times in PhoneGap Cordova 3
body: <p>cordova 3.1.0-0.2.0<br />
  Droid Razr M<br />
  Android 4.1.2<br />
  Windows 7<br /></p>
  
  <p>New to PhoneGap/Cordova. Running one of the filesystem demos from <a href="http://docs.phonegap.com/en/3.1.0/cordova_file_file.md.html#File" rel="nofollow">http://docs.phonegap.com/en/3.1.0/cordova_file_file.md.html#File</a>. Using "cordova run android" to compile the code and run it on the phone attached via USB. </p>
  
  <p>Problem #1: When the app first starts I get alert("1") twice and then nothing else.</p>
  
  <p>Problem #2: When I kick off the code via the button onclick I get the following alert pattern: 1, 2, 2, 3, 3, 4, 6, 5, 7, 4, 6, 5, 7. Some of that makes sense based on the code flow but most of them are firing twice.</p>
  
  <p>I'm suspecting problem #2 is being caused by some asynchronous calls hanging out from the first attempt but no matter how long I wait those events don't fire until I kick off the code via the button.</p>
  
  <p>So why is the requestFileSystem call failing even though it is waiting for deviceready and why is the other code getting intermingled?</p>
  
  <p>Any thoughts are appreciated.</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;FileReader Example&lt;/title&gt;
  
      &lt;script type="text/javascript" charset="utf-8" src="cordova.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript" charset="utf-8"&gt;
  
          // Wait for device API libraries to load
          //
          document.addEventListener("deviceready", onDeviceReady, false);
  
          // device APIs are available
          //
          function onDeviceReady() {
              alert("1");
              window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
          }
  
          function gotFS(fileSystem) {
              alert("2");
              fileSystem.root.getFile("readme.txt", null, gotFileEntry, fail);
          }
  
          function gotFileEntry(fileEntry) {
              alert("3");
              fileEntry.file(gotFile, fail);
          }
  
          function gotFile(file) {
              alert("4");
              readDataUrl(file);
              alert("5");
              readAsText(file);
          }
  
          function readDataUrl(file) {
              alert("6");
              var reader = new FileReader();
              reader.onloadend = function (evt) {
                  console.log("Read as data URL");
                  console.log(evt.target.result);
              };
              reader.readAsDataURL(file);
          }
  
          function readAsText(file) {
              alert("7");
              var reader = new FileReader();
              reader.onloadend = function (evt) {
                  console.log("Read as text");
                  console.log(evt.target.result);
              };
              reader.readAsText(file);
          }
  
          function fail(error) {
              alert("8");
              console.log(error.code);
          }
  
      &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;h1&gt;Example&lt;/h1&gt;
      &lt;p&gt;Read File&lt;/p&gt;
        &lt;button onclick="onDeviceReady();"&gt;Read File&lt;/button&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>