Is there an equivalent moveTaskToBack function

6 posts, 0 answers
  1. Joey Navarro
    Joey Navarro avatar
    16 posts
    Member since:
    Aug 2008

    Posted 12 Nov 2013 Link to this post

    I'm trying to prevent the back button on an android app from exiting the app.
  2. Markus
    Markus avatar
    205 posts
    Member since:
    Nov 2005

    Posted 13 Nov 2013 Link to this post

    Dear Joey

    I use the back butten exactely to close the app. 

    http://cordova.apache.org/docs/en/3.0.0/cordova_events_events.md.html#backbutton

    So I assume you could simply do: 

    <script type="text/javascript" charset="utf-8">
     
        // Wait for device API libraries to load
        //
        function onLoad() {
            document.addEventListener("deviceready", onDeviceReady, false);
        }
     
        // device APIs are available
        //
        function onDeviceReady() {
            // Register the event listener
            document.addEventListener("backbutton", onBackKeyDown, false);
        }
     
        // Handle the back button
        //
        function onBackKeyDown() {
    //simply to do nothing :-)
        }
     
        </script>


    Markus

  3. Joey Navarro
    Joey Navarro avatar
    16 posts
    Member since:
    Aug 2008

    Posted 13 Nov 2013 Link to this post

    No, I don't want the back button to close the app. I want it to behave the same way as if the home button was pressed.
  4. Markus
    Markus avatar
    205 posts
    Member since:
    Nov 2005

    Posted 14 Nov 2013 Link to this post

    Dear Joey

    Sorry for beeing a bit unclear on my answer. I just wanted to give you the code I am using to capture the back button usage by a user. 

    In my case I do show an confirm to close. But you could do what ever you want here: 

    function onBackKeyDown() {
    //simply to do nothing :-)
        }
      
        </script>


    That's why I wrote //simply do nothing.

    The above code should capture the case where a user presses the backbutton and will call the onBackKeyDown() function. And I would assume if you do nothing there the backbutton will do exactely this - nothing and therefore not close the app.

    Markus
  5. Joey Navarro
    Joey Navarro avatar
    16 posts
    Member since:
    Aug 2008

    Posted 14 Nov 2013 Link to this post

    You're right. The code you wrote will prevent the app from exiting. But what I really wanted was for the app to go to the background as if the home button was pressed. So I needed a method to call inside the onBackKeyDown function to accomplish this. The native Android API has a moveTaskToBack function that doesn't seem to be implemented in Phonegap.
  6. Markus
    Markus avatar
    205 posts
    Member since:
    Nov 2005

    Posted 15 Nov 2013 Link to this post

    Sorry Joey

    Since I did not know the moveTaskToBack function I just read your first line: I'm trying to prevent the back button on an android app from exiting the app.

    Just out of couriosity. Why do you want the back button to do the same button just next to it does by default. 

    - Would a user know why the back would do the same as home
    - Wouldn't a user simply use the home button to go home

    The most apps I have on my phone do either go back or ask if you want to close.

    Markus
Back to Top