I've got a function that makes use of the back button on Android Phones but for some reason when I use it, the app goes back 2 pages instead of the intended one.
This is what my code looks like at the moment:
function onBackKeyDown()
{
currentPage = $.mobile.activePage.attr('id');
if(currentPage == "createUser")
{
$.mobile.changePage("#logIn");
alert("Return To Login Page");
currentPage = "";
}
else if(currentPage == "cardDetails")
{
$.mobile.changePage("#createUser");
alert("Return To Create User");
currentPage = "";
}
else if(currentPage == "mainMenu")
{
$.mobile.changePage("#logIn");
alert("Return To Log In");
currentPage = "";
}
else if(currentPage == "locationPage")
{
$.mobile.changePage("#mainMenu");
alert("Return To Main Menu");
currentPage = "";
}
else if(currentPage == "editUserPage")
{
$.mobile.changePage("#mainMenu");
alert("Return To Main Menu");
currentPage = "";
}
else if(currentPage == "editCardDetailsPage")
{
$.mobile.changePage("#editUserPage");
alert("Return To Edit User");
currentPage = "";
}
else
alert("TEST");
}
For example if I were to be incardDetails
and I pushed the back button it would go back tocreateUser
and continue back tologIn
. Is there anything in my code that would cause this, I've tried resetting the currentPage to empty and added in else thinking that it was going though each of them individually when they were just if statements
EDIT: Requested Java Code:
import android.os.Bundle;
import org.apache.cordova.DroidGap;
public class FnBApp extends DroidGap {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
super.loadUrl("file:///android_asset/www/index.html");
}
}
Any help would be appreciated
John