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

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.

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

1 Like

Hi,

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

Thanks!

No, its still not fixed.

Thanks for the information

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

1 Like

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
}
}

4 Likes

Thank u man, it worked for me.

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){}

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];

Thanks, It worked for me.