2413
Views
7
Comments
Solved
Android Back Button Problem
Question

In Android, when the back button clicked, app will navigate to previous page that should be closed.

Take tutorial "Build a Mobile App in 5 min" as an example,

I go through:
1. Login Page (sign in) > 2. Home Screen (click an item) > 3. Todo Page (save data) > 4. Home Screen > 5. click Android back button > 6. previous Todo Page > 7. click Android back button > 8. Home Screen > 9. click Android back button > 10. Login page (without clicking logout button).

While, 6. should exit the app instead of going to previous Todo page or login page.

So how to prevent this?  

2019-09-17 09-11-00
João Pedro Abreu
Staff
Solution

Native apps generated by OutSystems are based on Cordova, which has a default behavior of forwarding the back event to the underlying WebView, making it act as a browser's back button.

You can probably implement your desired behavior by adding an event listener for the back button and issuing some commands to cordova. I found this stack overflow topic which doesn't have a marked solution, but may eventually help you: https://stackoverflow.com/questions/28766683/close-cordova-app-on-back-button 

UserImage.jpg
Simon Tsui

João Pedro Abreu wrote:

Native apps generated by OutSystems are based on Cordova, which has a default behavior of forwarding the back event to the underlying WebView, making it act as a browser's back button.

You can probably implement your desired behavior by adding an event listener for the back button and issuing some commands to cordova. I found this stack overflow topic which doesn't have a marked solution, but may eventually help you: https://stackoverflow.com/questions/28766683/close-cordova-app-on-back-button 

Thank you!


2017-10-04 03-06-15
Zainal Abidin

João Pedro Abreu wrote:

Native apps generated by OutSystems are based on Cordova, which has a default behavior of forwarding the back event to the underlying WebView, making it act as a browser's back button.

You can probably implement your desired behavior by adding an event listener for the back button and issuing some commands to cordova. I found this stack overflow topic which doesn't have a marked solution, but may eventually help you: https://stackoverflow.com/questions/28766683/close-cordova-app-on-back-button 

i interested with your solution, but i don't know how to implementation in outsystems. can you learn me ?


2018-11-06 14-26-44
Suraj Borade

Hi Simon,

That's interesting question. Let's wait for someone to answer this.

Thanks and Regards,

Suraj Borade

2019-09-17 09-11-00
João Pedro Abreu
Staff
Solution

Native apps generated by OutSystems are based on Cordova, which has a default behavior of forwarding the back event to the underlying WebView, making it act as a browser's back button.

You can probably implement your desired behavior by adding an event listener for the back button and issuing some commands to cordova. I found this stack overflow topic which doesn't have a marked solution, but may eventually help you: https://stackoverflow.com/questions/28766683/close-cordova-app-on-back-button 

UserImage.jpg
Simon Tsui

João Pedro Abreu wrote:

Native apps generated by OutSystems are based on Cordova, which has a default behavior of forwarding the back event to the underlying WebView, making it act as a browser's back button.

You can probably implement your desired behavior by adding an event listener for the back button and issuing some commands to cordova. I found this stack overflow topic which doesn't have a marked solution, but may eventually help you: https://stackoverflow.com/questions/28766683/close-cordova-app-on-back-button 

Thank you!


2017-10-04 03-06-15
Zainal Abidin

João Pedro Abreu wrote:

Native apps generated by OutSystems are based on Cordova, which has a default behavior of forwarding the back event to the underlying WebView, making it act as a browser's back button.

You can probably implement your desired behavior by adding an event listener for the back button and issuing some commands to cordova. I found this stack overflow topic which doesn't have a marked solution, but may eventually help you: https://stackoverflow.com/questions/28766683/close-cordova-app-on-back-button 

i interested with your solution, but i don't know how to implementation in outsystems. can you learn me ?


2019-09-24 18-41-25
Jorge Martins
 
MVP

Hi Simon,

You might want to check one of these:

- Exit On Back forge component: https://www.outsystems.com/forge/component/1805/exit-on-back

- Backbutton plugin for Cordova: https://www.npmjs.com/package/cordova-plugin-backbutton


2017-02-23 11-12-25
Eric Halim

Jorge Martins wrote:

Hi Simon,

You might want to check one of these:

- Exit On Back forge component: https://www.outsystems.com/forge/component/1805/exit-on-back

- Backbutton plugin for Cordova: https://www.npmjs.com/package/cordova-plugin-backbutton


Yes I recommend this component to control how the app should behave.


Note: That's why Apple don't like to have back button.

2020-07-21 19-28-50
Rajat Agrawal
Champion

Hello Simon Tsui,

It is a default functionality of mob application, its only store previous page information and is default behaviour.

Same problem I face when I am working on the mobile applications because outsystem use cordovo plugin. You need to modify the cordovo plugin by adding custom code in addEventListerner.

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