91
Views
2
Comments
How to handle screen backstack in mobile using system back button.
Question

I used below script.

function goToPreviousScreen(button) 

{  if (button == 1) {

       navigator.app.exitApp(); 

  } else { 

   return false; // No action, if presses "cancel"  }

}

function callConfirmation(){ 

navigator.notification.confirm(        "Are you sure you want to logout?",        goToPreviousScreen,        "Warning",        "Yes, Cancel"      );

}

function onBackButtonClick()

 {  document.addEventListener(    "backbutton",    function (e)

 {    $actions.GetBackButtonClick()     },  );

}

if ($actions.CheckDialogsPlugin()) {  onBackButtonClick();

}

2023-07-04 22-25-22
Mohamed Medhat

Hi @Prashant Andhale ,

The best way to handle this feature I found is to use a client variable, what you can do is to add client variable list of strings, each string represent the URL of the navigation stack, so each time you navigate to screen you add to this list an item (string url) and each time you click on the back button you pull from this list and remove it from the stack, remember to clear this list when ever you go to the home screen or whenever it is needed.

So basically what you are going to do is to add to Actions 1- pushToStackHistory sending string Url  to add item in the list and second 2- pullToStackHistory remove last item in the list

Then you need to handle back button navigation based on the the last url in the list

Best of luck

UserImage.jpg
Prashant Andhale

Thanks you @Mohamed Medhat .


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.