1

I have a HTML5+Jquery Mobile app, I converted the web view as Native android application using PhoneGap, I have written the following code to exit the application on Mobile. but this code not exiting the application. Please help me to resolve this issue.

jQuery :

<script type="text/javascript">
    $(document).on("pageinit", "#home", function (event) {
        $(document).on('click', '#exit', function (e) {
            if ( $('.ui-page-active').attr('id') == 'home') {
                navigator.app.exitApp();
            } else {
                history.back();             
            }
        }, false);             

    });
</script>

HTML

    <div data-role="footer" data-position="fixed">
        <a href="#" data-icon="back" class="ui-btn-left" data-transition="flip" data-theme="b" data-role="button" id="exit">Back</a>
        <h4> </h4>
        <a href="#page1" data-icon="forward" class="ui-btn-right" data-transition="flip" data-theme="b">Next</a>
    </div>
Able Alias
  • 3,824
  • 11
  • 58
  • 87
  • I don't see anything with class ui-page-active and id home. Did you check if this condition was good ? –  Nov 22 '13 at 16:40
  • @Gaëtan "
    and ".ui-page-active" currently active page class (jquery mobile class)
    – Able Alias Nov 22 '13 at 16:52
  • @Gaëtan such classes are dynamically added by jQM once page is rendered. – Omar Nov 22 '13 at 16:52
  • if you add a console.log or alert, do they fire? **edit:** if yes, they will fire once as you bound `click` event to `paginit`. – Omar Nov 22 '13 at 16:56
  • its firing in browser, let me check in AVD – Able Alias Nov 22 '13 at 16:57
  • @Omar I'm getting console message on AVD, "11-22 12:07:30.922: I/chromium(1677): [INFO:CONSOLE(14)] "test", source: file:///android_asset/www/Index.html (14)" – Able Alias Nov 22 '13 at 17:08
  • @Omar in console log, on page finished event happen its going to page 5 "11-22 12:19:50.952: D/Cordova(1884): onPageFinished(file:///android_asset/www/Index.html#page5) " – Able Alias Nov 22 '13 at 17:24
  • check this http://stackoverflow.com/questions/8602722/phonegap-android-back-button-close-app-with-back-button-on-homepage – Omar Nov 22 '13 at 17:26

2 Answers2

1

At last I found what I missed, I should add the cordova.js on my applications javascript library.

Able Alias
  • 3,824
  • 11
  • 58
  • 87
0

Try change $('.ui-page-active').attr('id') == 'home' with $.mobile.activePage.is('#home')

Gilbert Arafat
  • 441
  • 5
  • 10