Ionic monitors the Android return key to realize the “press again to exit” function

Apps on Android platform often encounter the function of "press again to exit the app" on the main page, so as to avoid exiting the app with only one click of the return key and improve the experience optimization.

1. This function requires us to use the registerbackbuttonaction method provided by ionic (register the hardware back button action)

Priority of the back button:

Return to previous view = 100

Close side menu = 150

Close template modal = 200

Close the pull-up menu action sheet = 300

Close dialog box pop = 400

Close the loading box loading = 500

Note: Return: function is a triggered function, which will log off the backbuttonaction.

If we don't want to register the return button to affect all pages, we need to call the return function again.

For example, if a pull-up menu is already displayed, the back button should close the pull-up menu instead of returning to a page view or closing an open model. Therefore, to realize the function of "press again to exit the app", we can set the priority to 101

2. Code implementation

In JS

In this way, we have simply implemented a "press again to exit the app function"

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>