I have googled, but all the useful articles are all describing how to handle the back button in NavigationView, but I just use the common view like below.
Ext.define('emall.view.MyPage', {
extend: 'Ext.Container',
alias: 'widget.mypage',
requires: [
'emall.view.topplus',
'Ext.TitleBar',
'Ext.Button',
'Ext.Toolbar'
],
I am do changes on the existing app, so I can not change the base architecture. So I am wondering how to handle the back button?
I know below way can capture the back button event.(I added the below method to app.js)
if (Ext.os.is('Android')) {
document.addEventListener("backbutton", Ext.bind(onBackKeyDown, this), false);
function onBackKeyDown(eve) {
eve.preventDefault();
//do something
alert('back button pressed');
history.back();
}
}
But what can I do in the method onBackKeyDown ? Since this event will be fired when I click the back button no matter which page I am staying. So I can not go to the previous page like Ext.Viewport.animateActiveItem('xxxx') since I do not know the current page I am staying.
If I can get the current page name, I can handle it like below.
if(currentpage=='xxx')
Ext.Viewport.animateActiveItem('profile', {
type : 'slide',
direction:'left'
});
Use this code:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {if (navigator.userAgent.match("Android"))
{ document.addEventListener("backbutton", onBackKeyDown, true); }
}
function onBackKeyDown(e) {
if (window.location.hash === "#splashviewRoute") {
navigator.app.exitApp();
}
else {
window.history.back();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.