MobileBlazorBindings icon indicating copy to clipboard operation
MobileBlazorBindings copied to clipboard

Android back button in hybrid closes the app

Open AmirImam opened this issue 5 years ago • 7 comments

Hi, of course the normal behavior is close the app on back button, so how to avoid this action and make it go to the previous page ?

AmirImam avatar Nov 11 '20 19:11 AmirImam

Ah, you want Android Back button to navigate back in the Web View of the hybrid app?

Eilon avatar Nov 11 '20 19:11 Eilon

Ah, you want Android Back button to navigate back in the Web View of the hybrid app?

Yes exactly

AmirImam avatar Nov 11 '20 19:11 AmirImam

Got it, we'll have to take a look at this, I'm sure there's a way to do it.

Eilon avatar Nov 11 '20 19:11 Eilon

Since it's a Webview , you can use javascript window.history.back() and override default back button press in Mainactivity.cs I hope it helps :)

ep0x avatar Feb 06 '21 11:02 ep0x

@Eilon any update on this?

Thanks

ozzioma avatar Mar 06 '21 03:03 ozzioma

@ozzioma no update at this time. For now this is considered a low priority item but if someone wants to investigate and propose a fix, we could certainly look at including the fix in the next update.

Eilon avatar Mar 08 '21 17:03 Eilon

I know i'm kind of reviving an old issue, but i managed to handle the back button using Xamarin's OnBackPressed override in MainActivity.cs. It catches the event, and i use the already referenced hybrid project with a "bridge-like" singleton class which contains a reference to a navigation manager wrapper, which handles the history. It works properly, but it requires a loading screen which makes the injection of the service first, otherwise it throws "not initialized" error. Another problem occurs when you minimize and resume the app, you need to save the history somehow, or it resets. I'm going to try saving it through the OnSaveInstance override.

ezesil avatar Dec 06 '21 15:12 ezesil