How to increment/save a variable in html activity?

edited February 2014 in Android SDK Programming
I'd like to count how many times someone pushed a button on various html pages in my html activity (e.g. a test with yes/no answers) and then show different content depending on the value of the counter.

How can I do this in html with Andromo?

Comments

  • C'mon people are you telling me that there's no way to specify a variable in the html pages, that can be saved as the user hops from page to page?
  • That's javascript at work to do that - I work with js and i know there will be a way to do it, but I'm a bit stuck on that one (That wasn't much help sorry)  :)
  • You gave me hope :)
  • I've found that saving cookies work alright from a php standpoint if you have a webserver (using web activity of course). Cookies might also work with javascript using the html archive activity but I haven't tried it.
  • My app is offline - I don't want to go out to the web just to store this minor info.
  • edited February 2014
    It looks like you might be able to do it with HTML5 Web Storage:

    http://www.w3schools.com/html/html5_webstorage.asp
  • @tholyoak - That is SO useful awsome resource  :)
  • Unfortunately Andromo does not fully support HTML 5, especially re the storage feature (which is one of the top features in HTML 5). I'm not sure what other HTML 5 features aren't supported by Andromo.

    I just made a little app with 2 html pages and although they both reference the same counter (have a button to increment counter each time I press it), each html page has it's local data so page A might say 9 but on the page B I see 22 - this is maintained when I switch back and forth between the pages, but unfortunately I can't have just one counter they both can share.

    It makes no difference if I use sessionStorage or localStorage variables as outlined in the HTML 5 spec here: http://dev.w3.org/html5/webstorage/ - although I would have thought the localStorage counter would have persisted.

    I found a post from a few months ago where support confirmed this missing feature: ref: http://support.andromo.com/discussions/questions/4126-html5-localstorage-issue-with-andromo

    Too bad as this limits the power of using HTLM 5 for offline games and other apps where you want to have some local data saved... as explained here: http://www.html5rocks.com/en/features/storage
  • I have now also tried saving to a cookie and incrementing each time a button is pushed. This works fine on a browser (desktop) but I get "null" for the counter value when using the Andromo html archive activity for this code. The cookie is not getting saved.

    It seems that Andromo simply doesn't let you store anything on the phone using cookies or HTML 5 storage, which makes offline apps quite limited
    :-w
  • Cookies are not supposed to be supported on web pages that aren't served from a web server. Some browsers support them anyway; Chrome does not (unless you invoke a commandline option, but that obviously doesn't work on Android).
  • I've looked into this a little more, and the LocalStorage issue you describe is beyond our control because multiple Android WebViews can't share the same data with LocalStorage, at least in the API target version Andromo is currently compiled with (API level 17). That functionality is all handled in the core of Android's WebView code.

    I suspect there may be better handling for it in the most recent Android SDK update (API level 19) since the WebView has been changed to be based on Chrome, however I haven't confirmed that. We do plan to update the SDK in the near future though either way.

    Beyond HTML5's LocalStorage, we may look at alternate ways to store data from HTML in the future.
  • Great Todo feature indeed. I can't wait. Thanks @pdog for all the iterations. Andromo would be a more powerful tool with this feature.

Sign In or Register to comment.