0

I have implemented a hybrid web view in my Xamarin PCL app.

I am calling a C# function from an Html page using JavaScript in the aforementioned, hybrid web view.

The problem is that although my function is being called, an exception is thrown when I try to redirect from it.

Android.Util.AndroidRuntimeException:

Only the original thread that created a view hierarchy can touch its views.

at System.Runtime.ExceptionServices.ExceptionDispatchInfo.

My code is as follows:

var isValid = AreCredentialsCorrect(user);

if (isValid)
{
    try
    {
        await Navigation.PushAsync(new UserDashboard("local.html?auth_admin=true"));

    }
    catch { }

}

public UserDashboard(string uriname)
{
    InitializeComponent();

    hybridWebView.Uri = uriname;

    hybridWebView.RegisterAction(data => userLogin(data));

}

1 Answer 1

3

Sounds like you're trying to update UI from a background thread. Try doing the navigation from the main thread:

Device.BeginInvokeOnMainThread(async () => await Navigation.PushAsync(new UserDashboard("local.html?auth_admin=true")));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.