2

I know this sounds like a weird question.

I have a Xamarin.Android app. I'm going through my code and cleaning up stuff that was too aggressively wrapped with calls to RunOnUiThread. My understanding is that code that runs in response to UI events, for example, is already on the UI thread and therefore doesn't need to be wrapped. I don't like the idea of RunOnUiThread calls just sprinkled everywhere like magical pixie dust.

I've removed a bunch of these calls, and preserved the ones I think are necessary. When I run the app, everything works great. But not even a single crash on the first try seemed almost too good to be true, so as a sanity check, I tried to intentionally crash the app by adding UI update code in places where I expected it to be required to be wrapped by RunOnUiThread. However, nothing I do causes that effect!

This makes me concerned that there is some magic happening somewhere that is preventing me from seeing a problem.

The last thing I tried, which I thought would surely crash the app, was to use a Java.Util.Timer to execute a Java.Util.TimerTask that sets the Alpha on an ImageView to 0.5. But still the app hums merrily along!

Now I am totally suspicious that something -- maybe some new OS feature -- is silently fixing things but that customers running in some other configuration will experience crashes. I want to see the error so that I can have confidence that when I don't see it, things are OK.

So, what can I do to intentionally get the Only the original thread that created a view hierarchy can touch its views error?

Brian Rak
  • 4,912
  • 6
  • 34
  • 44
  • 2
    Maybe checking in which thread you are can be of help: https://stackoverflow.com/questions/11411022/how-to-check-if-current-thread-is-not-main-thread – Piovezan Sep 28 '18 at 22:11
  • @Piovezan, thank you, that is really useful. I was able to confirm that the code that runs in a TimerTask is indeed not running in the UI thread. But still, changing a UI component produced no ill effects. This only heightens my concern that something is going on that is "helping" to prevent errors that might occur in a different environment. I'd really love to figure this out. – Brian Rak Sep 28 '18 at 23:28

0 Answers0