Bug 34782 - Android - OnLoadFinished is never called
Summary: Android - OnLoadFinished is never called
Status: RESOLVED INVALID
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.5.0
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-10-12 16:29 UTC by christine.blanda
Modified: 2017-02-09 23:37 UTC (History)
6 users (show)

Tags: ac
Is this bug a regression?: ---
Last known good build:


Attachments
Test Application (238.08 KB, application/x-zip-compressed)
2015-10-12 16:29 UTC, christine.blanda
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED INVALID

Description christine.blanda 2015-10-12 16:29:45 UTC
Created attachment 13293 [details]
Test Application

Take the testApp attached and change the targetUrl in WebPage.cs to a working Url (like www.xamarin.com).  In MyWebView, add breakpoints to ln 10 (Navigated += OnLoadFinished) and ln 15 (first line of OnLoadFinished) then run.  The first breakpoint will be hit, the second one will not, and the Alert will not display.
Comment 1 adrianknight89 2016-10-16 06:16:26 UTC
Christine,

You're replacing the existing WebViewClient with your own:

// lets get a reference to the native control
var nativeWebView = Control;
nativeWebView.SetWebViewClient(new MyWebViewClient());

XF's implementation of WebViewClient does all the plumbing such as raising the Navigated event. It might be possible to expose a WebViewClient property so it can be overridden, but you'd still be responsible for hooking things up properly.

See https://github.com/xamarin/Xamarin.Forms/blob/74cb5c4a97dcb123eb471f6b1dffa1267d0305aa/Xamarin.Forms.Platform.Android/Renderers/WebViewRenderer.cs#L154

Why would you want a custom WebViewClient?
Comment 2 christine.blanda 2016-10-17 13:14:52 UTC
Yes, that is because I had to override ShouldOverrideUrlLoading.  I see that is now marked as obsolete, how should that be handled instead?
Comment 3 adrianknight89 2016-10-17 14:13:12 UTC
You should continue overriding the deprecated method (for apis <24) as well as the new one (for apis >= 24).

I need to look at Xamarin's implementation, but the new one should look something like this:

public override bool ShouldOverrideUrlLoading(AWebView view, IWebResourceRequest request)

You could get the previous string parameter like so: request.Url.ToString().
Comment 4 Jimmy [MSFT] 2017-02-09 23:37:21 UTC
I can reproduce this issue using the attached repro project with Forms 1.5.0.447 and 2.3.3.180. However, as mentioned in comment #1, this is due to using a custom renderer to replace the default WebViewClient so the Navigated event is never sent. Without the custom renderer, the app runs as expected.