Reputation: 621
I am making an Android game using MonoGame and Xamarin's Mono for Android. At certain points during the game I add an inner-active banner ad by adding it to the view as follows:
var adLayout = new ViewGroup.MarginLayoutParams(
ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.FillParent);
_iaBanner.SetGravity(GravityFlags.NoGravity);
_view.AddView(_iaBanner, adLayout);
This code is executed within the XNA update loop.
All is fine and the ad displays, but when it is tapped at any time, it raises the following exception:
CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
I do not control at all when input handling for this ad happens. All I can and do control is when to add/remove from the Activity's view.
Any ideas how to fix this? Thanks.
Upvotes: 1
Views: 129
Reputation: 2188
Can you wrap that call with RunOnUiThread(() => {...Your Code Here...});
Upvotes: 0