title: History.pushState and traversing through history - PhoneGap/Android
body: <p>I'm writing an Android application for a client. I've been using my own framework for the creation of the app.</p>
  
  <p>This framework works without issue on iPhones, but when I came to apply it to Android/Phonegap I have been getting issues with the back button. My solution was to make a call to the History object to create items as different pages were viewed. The gist of this code is as follows:</p>
  
  <pre><code>        'hook_call': function (name, data, callback, skip_history) {
  
              if (typeof callback != 'function') {
                  callback = function () {};
              }
  
              app.handlers[name].call(this, data, callback);
              window.app.current_hook = name;
  
              // Manage history
              if(!skip_history ) {
                  history.pushState({'page': name, 'data': data}, null, '#'+name);
              }
  
          }
  </code></pre>
  
  <p>My onpopstate function:</p>
  
  <pre><code>// Manage history
  window.onpopstate = function(event) {
      try {
          if(window.app.current_hook != event.state.page)
              window.app.hook_call(event.state.page, event.state.data);
      }
      catch(e) {}
  };
  </code></pre>
  
  <p>So, this adds items properly. However if I go say three levels into the history (<code>home</code>, <code>listings</code> -> <code>view_listing</code>) and press back from <code>view_listing</code> I will be taken to the <code>listings</code> section, which is correct, but any further presses leaves me at <code>listings</code>, it won't move any further back than that.</p>
  
  <p>When I look in the log after the navigation steps I just explained, I see these spurious items:</p>
  
  <pre><code>04-16 10:22:39.320: D/CordovaWebView(1148): The current URL is: file:///android_asset/www/index.html#listing
  04-16 10:22:39.320: D/CordovaWebView(1148): The URL at item 0 is:file:///android_asset/www/index.html
  04-16 10:22:39.400: D/CordovaWebView(1148): The URL at index: 0is file:///android_asset/www/index.html
  04-16 10:22:39.400: D/CordovaWebView(1148): The URL at index: 1is file:///android_asset/www/index.html#welcome
  04-16 10:22:39.400: D/CordovaWebView(1148): The URL at index: 2is file:///android_asset/www/index.html#listings
  04-16 10:22:39.410: D/CordovaWebView(1148): The URL at index: 3is file:///android_asset/www/index.html#listing
  </code></pre>
  
  <p>I should add that to get to the different pages, <code>hook_call()</code> is called for example when listings are tapped or buttons are pressed.</p>
  
  <p>This scenario is true for any other combination of navigation through the app. </p>
  
  <p>Has anyone had any experience with this or something similar?</p>