Hard back button on <ion-select> does not close pop up (Android)


#1

When you press the hard back button on ion-select, the pop up does not close, instead it changes the background page. The same issue is seen even for DatePicker. when the pop ups are triggered from html, there is no way we can close it, unless we press “cancel”/“ok” button, or if we touch around the pop up screen. Since android users like to use the hard back button, it is of utmost importance to fix this issue.


#2

Can you open an issue for this?
It should close in my opinion, but we may have missed this.


#3

Hi,

Did you find a solution to this?
I am stuck at similar situation. Any help would be appreciated!

Thanks!


#4

No, its still not fixed.


#5

Thanks for the information


#6

Team ionic please provide solution for actionsheet dismiss on hardware back button.


#7

Find the solution:

public initializeBackButtonCustomHandler(): void {
this.unregisterBackButtonAction = this.platform.registerBackButtonAction(() => {
this.customHandleBackButton();
}, 10);
}
private customHandleBackButton(): void {
const overlayView = this.app._overlayPortal._views[0];
if (overlayView && overlayView.dismiss) {
overlayView.dismiss();// it will close the modals, alerts
} else {
this.navCtrl.setRoot(‘HomePage’);//do what do you want to do
}
}


#8

Thank u man, it worked for me.


#9

Before you implement @jagationic’s logic, make sure to import:
import { IonicApp } from ‘ionic-angular’;

and add this to the constructor:
constructor(private app: IonicApp){}


#10

Tnx buddy its great solution . i stuck in situation that what is app and how it import . So from other example i add it .
import {IonicApp } from ‘ionic-angular’;

also add
private ionicApp: IonicApp

take it
onst overlayView = this.ionicApp._overlayPortal._views[0];