Skip to content

Android OnRedraw exception - not on the UI thread #9

Description

@johncdoherty

I am receiving the following error on Android fromLiteHtmlMaui.Handlers.AndroidLiteHtmlView.OnRedraw() in a .NET9 MAUI application when attempting to utilize the LiteHtml.MAUI from within a collection view. This results in an application crash, instability, and/or rendering issues in other pages. I believe the AndroidLiteHtmlView.OnRedraw() should be implemented in the same fashion as it is on iOS, usingInvokeOnMainThread.

Exception: AggregateException
Message: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (Only the original thread that created a view hierarchy can touch its views. Expected: main Calling: Thread-13)
Stack Trace: 
Inner Exception: AndroidRuntimeException
Inner Message: **Only the original thread that created a view hierarchy can touch its views. Expected: main** Calling: Thread-13
Inner Stack Trace:    at Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualVoidMethod(JniObjectReference instance, JniObjectReference type, JniMethodInfo method, JniArgumentValue* args) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/net8.0/JniEnvironment.g.cs:line 20831
   at Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualVoidMethod(String encodedMember, IJavaPeerable self, JniArgumentValue* parameters) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:line 75
   at Android.Views.View.RequestLayout() in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net9.0/android-35/mcw/Android.Views.View.cs:line 21496
   at **LiteHtmlMaui.Handlers.AndroidLiteHtmlView.OnRedraw()**
   at LiteHtmlMaui.Handlers.Native.LiteHtmlDocumentView`3.<>c__DisplayClass20_0.<<LoadImageCb>b__0>d[[Android.Graphics.Canvas, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065],[Android.Graphics.Bitmap, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065],[Android.Graphics.Typeface, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]].MoveNext()

Usage:

<CollectionView ItemsSource="{Binding GuideData}" x:Name="GuideDataCollectionView">
	<CollectionView.ItemTemplate>
		<DataTemplate x:DataType="scg:KeyValuePair(sys:String,sys:String)">
			<VerticalStackLayout Spacing="2" Margin="0,8,0,8">
				<Label Text="{Binding Key}" Style="{StaticResource SubTitleLabel}" />
				<html:LiteHtml Html="{Binding Value}" TextColor="{AppThemeBinding Light={StaticResource LightColorText1}, Dark={StaticResource DarkColorText1}}"/>
			</VerticalStackLayout>
		</DataTemplate>
	</CollectionView.ItemTemplate>
</CollectionView>
Image

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions