Hmm the code I am using is almost identical to yours. In fact I took inspiration from this post.
My Activity1.cs class has:
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
Xamarin.Essentials.Platform.Init(this, bundle);
_game = new Game1();
_view = _game.Services.GetService(typeof(View)) as View;
SetContentView(_view);
_game.Run();
}
And my thread method is in my game implementation is (I have omitted most of the functional code to reduce noise in this thread):
private async void MakePurchase(string productId)
{
var purchaseIsSuccessful = await ExecutePurchase(productId, "");
if (purchaseIsSuccessful)
{
//PURCHASE SUCCESSFUL
}
else
{
//PURCHASE FAILED
}
}
private async Task<bool> ExecutePurchase(string productId, string payload)
{
var billing = CrossInAppBilling.Current;
try
{
await billing.ConnectAsync();
var purchase = await billing.PurchaseAsync(productId, ItemType.InAppPurchaseConsumable, payload);
// purchase handling
}
catch (InAppBillingPurchaseException purchaseEx)
{
// error handling
}
finally
{
await billing.DisconnectAsync();
}
return false;
}
Where I then execute the MakePurchase method with the product id such as:
MakePurchase("android.test.purchased");
I still don’t understand how/why this problem occurs.