Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android.Util.AndroidRuntimeException: Only the original thread that created a view hierarchy can touch its views. #14128

Closed
SorenBech2 opened this issue Mar 22, 2023 · 9 comments
Labels
area-controls-image Image control platform/android 🤖 s/duplicate 2️⃣ This issue or pull request already exists s/triaged Issue has been reviewed t/bug Something isn't working
Milestone

Comments

@SorenBech2
Copy link

Description

An app that based on a selection made through a picker list, displays the object information - including the object image – of the selected object.

Picking an item for the 2nd time the image does not show and the below error message is generated. (The error does not occur when code is compiled to windows which leads to a suspicion of a bug in the Android generated code.)
For full description please see below.
Maui Databinding issue.docx

Steps to Reproduce

Debug the code in the repository (link below).

Picking an item for the 2nd time the image does not show and the below error message is generated.

OBS: To reproduce you need to pick a subject and then pick a different subject from the picker list.

When a 3rd subject is selected everything works fine (as well as for the 4th, 5th, and so on) The error only occur for the 2nd selection! (In a few tests, this error occurs after 3 selections not 2, but predominantly after 2 selections).
It is unclear to me which code executed in another thread but the UI thread creates the error. I have included a check on the thread which indicated the code is executed in the UI thread - as well as tried to include the code in a MainThread.BeginInvokeOnMainThread without any impact on the error.

Link to public reproduction project repository

https://github.com/SorenBech2/DataBindingTest

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 12.1 - API 32 & 13.0 API 33

Did you find any workaround?

No workaround found. Tried to include the code in a MainThread.BeginInvokeOnMainThread without any impact on the error.

Relevant log output

[0:] Microsoft.Maui.StreamImageSourceService: Warning: Unable to load image stream.

Android.Util.AndroidRuntimeException: Only the original thread that created a view hierarchy can touch its views.
   at Java.Interop.JniEnvironment.StaticMethods.CallStaticVoidMethod(JniObjectReference type, JniMethodInfo method, JniArgumentValue* args) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/net7.0/JniEnvironment.g.cs:line 13250
   at Java.Interop.JniPeerMembers.JniStaticMethods.InvokeVoidMethod(String encodedMember, JniArgumentValue* parameters) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniStaticMethods.cs:line 97
   at Microsoft.Maui.PlatformInterop.LoadImageFromStream(ImageView imageView, Stream inputStream, IImageLoaderCallback callback) in D:\a\_work\1\s\src\Core\src\obj\Release
et7.0-android\generated\src\Microsoft.Maui.PlatformInterop.cs:line 443
   at Microsoft.Maui.StreamImageSourceService.LoadDrawableAsync(IImageSource imageSource, ImageView imageView, CancellationToken cancellationToken) in D:\a\_work\1\s\src\Core\src\ImageSources\StreamImageSourceService\StreamImageSourceService.Android.cs:line 28
  --- End of managed Android.Util.AndroidRuntimeException stack trace ---
android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
	at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:9461)
	at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:1825)
	at android.view.View.requestLayout(View.java:25757)
	at android.view.View.requestLayout(View.java:25757)
	at android.view.View.requestLayout(View.java:25757)
	at android.view.View.requestLayout(View.java:25757)
	at android.view.View.requestLayout(View.java:25757)
	at android.view.View.requestLayout(View.java:25757)
	at android.view.View.requestLayout(View.java:25757)
	at androidx.drawerlayout.widget.DrawerLayout.requestLayout(DrawerLayout.java:1353)
	at android.view.View.requestLayout(View.java:25757)
	at android.view.View.requestLayout(View.java:25757)
	at android.view.View.requestLayout(View.java:25757)
	at android.view.View.requestLayout(View.java:25757)
	at android.view.View.requestLayout(View.java:25757)
	at android.view.View.requestLayout(View.java:25757)
	at androidx.recyclerview.widget.RecyclerView.requestLayout(RecyclerView.java:4586)
	at android.view.View.requestLayout(View.java:25757)
	at android.view.View.requestLayout(View.java:25757)
	at android.view.View.requestLayout(View.java:25757)
	at android.view.View.requestLayout(View.java:25757)
	at androidx.core.widget.NestedScrollView.requestLayout(NestedScrollView.java:2075)
	at android.view.View.requestLayout(View.java:25757)
	at android.view.View.requestLayout(View.java:25757)
	at android.view.View.requestLayout(View.java:25757)
	at android.widget.ImageView.setImageDrawable(ImageView.java:601)
	at androidx.appcompat.widget.AppCompatImageView.setImageDrawable(AppCompatImageView.java:112)
	at com.microsoft.maui.glide.MauiCustomViewTarget.onResourceCleared(MauiCustomViewTarget.java:30)
	at com.bumptech.glide.request.target.CustomViewTarget.onLoadCleared(CustomViewTarget.java:210)
	at com.bumptech.glide.request.SingleRequest.clear(SingleRequest.java:337)
	at com.bumptech.glide.request.ErrorRequestCoordinator.clear(ErrorRequestCoordinator.java:48)
	at com.bumptech.glide.manager.RequestTracker.clearAndRemove(RequestTracker.java:70)
	at com.bumptech.glide.RequestManager.untrack(RequestManager.java:660)
	at com.bumptech.glide.Glide.removeFromManagers(Glide.java:913)
	at com.bumptech.glide.RequestManager.untrackOrDelegate(RequestManager.java:647)
	at com.bumptech.glide.RequestManager.clear(RequestManager.java:624)
	at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:811)
	at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:780)
	at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:771)
	at com.microsoft.maui.PlatformInterop.prepare(PlatformInterop.java:229)
	at com.microsoft.maui.PlatformInterop.loadInto(PlatformInterop.java:234)
	at com.microsoft.maui.PlatformInterop.loadImageFromStream(PlatformInterop.java:265)

  --- End of managed Android.Util.AndroidRuntimeException stack trace ---
android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
	at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:9461)
	at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:1825)
	at android.view.View.requestLayout(View.java:25757)
	at android.view.View.requestLayout(View.java:25757)
	at android.view.View.requestLayout(View.java:25757)
	at android.view.View.requestLayout(View.java:25757)
	at android.view.View.requestLayout(View.java:25757)
	at android.view.View.requestLayout(View.java:25757)
	at android.view.View.requestLayout(View.java:25757)
	at androidx.drawerlayout.widget.DrawerLayout.requestLayout(DrawerLayout.java:1353)
	at android.view.View.requestLayout(View.java:25757)
	at android.view.View.requestLayout(View.java:25757)
	at android.view.View.requestLayout(View.java:25757)
	at android.view.View.requestLayout(View.java:25757)
	at android.view.View.requestLayout(View.java:25757)
	at android.view.View.requestLayout(View.java:25757)
	at androidx.recyclerview.widget.RecyclerView.requestLayout(RecyclerView.java:4586)
	at android.view.View.requestLayout(View.java:25757)
	at android.view.View.requestLayout(View.java:25757)
	at android.view.View.requestLayout(View.java:25757)
	at android.view.View.requestLayout(View.java:25757)
	at androidx.core.widget.NestedScrollView.requestLayout(NestedScrollView.java:2075)
	at android.view.View.requestLayout(View.java:25757)
	at android.view.View.requestLayout(View.java:25757)
	at android.view.View.requestLayout(View.java:25757)
	at android.widget.ImageView.setImageDrawable(ImageView.java:601)
	at androidx.appcompat.widget.AppCompatImageView.setImageDrawable(AppCompatImageView.java:112)
	at com.microsoft.maui.glide.MauiCustomViewTarget.onResourceCleared(MauiCustomViewTarget.java:30)
	at com.bumptech.glide.request.target.CustomViewTarget.onLoadCleared(CustomViewTarget.java:210)
	at com.bumptech.glide.request.SingleRequest.clear(SingleRequest.java:337)
	at com.bumptech.glide.request.ErrorRequestCoordinator.clear(ErrorRequestCoordinator.java:48)
	at com.bumptech.glide.manager.RequestTracker.clearAndRemove(RequestTracker.java:70)
	at com.bumptech.glide.RequestManager.untrack(RequestManager.java:660)
	at com.bumptech.glide.Glide.removeFromManagers(Glide.java:913)
	at com.bumptech.glide.RequestManager.untrackOrDelegate(RequestManager.java:647)
	at com.bumptech.glide.RequestManager.clear(RequestManager.java:624)
	at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:811)
	at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:780)
	at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:771)
	at com.microsoft.maui.PlatformInterop.prepare(PlatformInterop.java:229)
	at com.microsoft.maui.PlatformInterop.loadInto(PlatformInterop.java:234)
	at com.microsoft.maui.PlatformInterop.loadImageFromStream(PlatformInterop.java:265)
@SorenBech2 SorenBech2 added the t/bug Something isn't working label Mar 22, 2023
@jsuarezruiz jsuarezruiz added the area-controls-image Image control label Mar 22, 2023
@ghost ghost added the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label Mar 22, 2023
@jsuarezruiz jsuarezruiz added platform/android 🤖 and removed legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor labels Mar 22, 2023
@rachelkang rachelkang added this to the Backlog milestone Mar 22, 2023
@ghost
Copy link

ghost commented Mar 22, 2023

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

@Eilon Eilon added the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label Mar 24, 2023
@jstedfast
Copy link
Member

Reproduced and definitely seems to be similar to the issue I've been working on fixing.

Will test with my fix momentarily.

@jstedfast
Copy link
Member

This is a duplicate of issue #14052

@jstedfast jstedfast added the s/duplicate 2️⃣ This issue or pull request already exists label Mar 27, 2023
@SorenBech2
Copy link
Author

SorenBech2 commented Mar 28, 2023 via email

@jstedfast
Copy link
Member

First I need to figure out how to write a unit test and then I have to get my patch reviewed/accepted/merged and then a release has to be made (which I believe is done on a fixed schedule and I'm not sure what that schedule is - I'm new to the team and am temporarily helping them out).

@SorenBech2
Copy link
Author

SorenBech2 commented Mar 28, 2023 via email

@Zhanglirong-Winnie Zhanglirong-Winnie added s/triaged Issue has been reviewed s/try-latest-version Please try to reproduce the potential issue on the latest public version labels Jun 19, 2023
@ghost
Copy link

ghost commented Jun 19, 2023

Hi @SorenBech2. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.

You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@Zhanglirong-Winnie
Copy link

Verified this issue with Visual Studio Enterprise 17.7.0 Preview 1.0. Not repro on android platform with sample project.
DataBinding.zip
14128

@SorenBech2
Copy link
Author

SorenBech2 commented Jul 17, 2023 via email

@ghost ghost removed the s/try-latest-version Please try to reproduce the potential issue on the latest public version label Jul 17, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Aug 16, 2023
@Eilon Eilon removed the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label May 10, 2024
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-image Image control platform/android 🤖 s/duplicate 2️⃣ This issue or pull request already exists s/triaged Issue has been reviewed t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants