Skip to content

Commit d8d6034

Browse files
Still not quite working, but pushing my change
1 parent bfb29db commit d8d6034

File tree

1 file changed

+38
-7
lines changed
  • source/com.android.billingclient/billing/Additions

1 file changed

+38
-7
lines changed

source/com.android.billingclient/billing/Additions/Additions.cs

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@
44

55
namespace Android.BillingClient.Api
66
{
7+
public partial class BillingResult
8+
{
9+
internal BillingResult Clone()
10+
{
11+
return BillingResult.NewBuilder()
12+
.SetResponseCode((int)ResponseCode)
13+
.SetDebugMessage(DebugMessage)
14+
.SetOnPurchasesUpdatedSubResponseCode(OnPurchasesUpdatedSubResponseCode)
15+
.Build();
16+
}
17+
}
18+
719
public class ConsumeResult
820
{
921
public BillingResult BillingResult { get; set; }
@@ -196,7 +208,10 @@ internal class InternalAcknowledgePurchaseResponseListener : Java.Lang.Object, I
196208
public Action<BillingResult> AcknowledgePurchaseResponseHandler { get; set; }
197209

198210
public void OnAcknowledgePurchaseResponse(BillingResult result)
199-
=> AcknowledgePurchaseResponseHandler?.Invoke(result);
211+
{
212+
// Create a copy of the BillingResult to ensure it stays alive after the callback
213+
AcknowledgePurchaseResponseHandler?.Invoke(result.Clone());
214+
}
200215
}
201216

202217
internal class InternalBillingClientStateListener : Java.Lang.Object, IBillingClientStateListener
@@ -209,36 +224,51 @@ public void OnBillingServiceDisconnected()
209224
=> BillingServiceDisconnectedHandler?.Invoke();
210225

211226
public void OnBillingSetupFinished(BillingResult result)
212-
=> BillingSetupFinishedHandler?.Invoke(result);
227+
{
228+
// Create a copy of the BillingResult to ensure it stays alive after the callback
229+
BillingSetupFinishedHandler?.Invoke(result.Clone());
230+
}
213231
}
214232

215233
internal class InternalConsumeResponseListener : Java.Lang.Object, IConsumeResponseListener
216234
{
217235
public Action<BillingResult, string> ConsumeResponseHandler { get; set; }
218236
public void OnConsumeResponse(BillingResult result, string str)
219-
=> ConsumeResponseHandler?.Invoke(result, str);
237+
{
238+
// Create a copy of the BillingResult to ensure it stays alive after the callback
239+
ConsumeResponseHandler?.Invoke(result.Clone(), str);
240+
}
220241
}
221242

222243
internal class InternalPriceChangeConfirmationListener : Java.Lang.Object //, IPriceChangeConfirmationListener
223244
{
224245
public Action<BillingResult> PriceChangeConfirmationHandler { get; set; }
225246
public void OnPriceChangeConfirmationResult(BillingResult result)
226-
=> PriceChangeConfirmationHandler?.Invoke(result);
247+
{
248+
// Create a copy of the BillingResult to ensure it stays alive after the callback
249+
PriceChangeConfirmationHandler?.Invoke(result.Clone());
250+
}
227251
}
228252

229253
internal class InternalPurchaseHistoryResponseListener : Java.Lang.Object, IPurchaseHistoryResponseListener
230254
{
231255
public Action<BillingResult, IList<PurchaseHistoryRecord>> PurchaseHistoryResponseHandler { get; set; }
232256

233257
public void OnPurchaseHistoryResponse(BillingResult result, IList<PurchaseHistoryRecord> history)
234-
=> PurchaseHistoryResponseHandler?.Invoke(result, history);
258+
{
259+
// Create a copy of the BillingResult to ensure it stays alive after the callback
260+
PurchaseHistoryResponseHandler?.Invoke(result.Clone(), history);
261+
}
235262
}
236263

237264
internal class InternalPurchasesUpdatedListener : Java.Lang.Object, IPurchasesUpdatedListener
238265
{
239266
public Action<BillingResult, IList<Purchase>> PurchasesUpdatedHandler { get; set; }
240267
public void OnPurchasesUpdated(BillingResult result, IList<Purchase> purchases)
241-
=> PurchasesUpdatedHandler?.Invoke(result, purchases);
268+
{
269+
// Create a copy of the BillingResult to ensure it stays alive after the callback
270+
PurchasesUpdatedHandler?.Invoke(result.Clone(), purchases);
271+
}
242272
}
243273

244274
[Obsolete("Use QueryProductDetailsAsync(QueryProductDetailsParams) instead")]
@@ -256,7 +286,8 @@ internal class InternalProductDetailsResponseListener : Java.Lang.Object, IProdu
256286

257287
public void OnProductDetailsResponse(BillingResult result, QueryProductDetailsResult queryResult)
258288
{
259-
ProductDetailsResponseHandler?.Invoke(result, queryResult?.ProductDetailsList);
289+
// Create a copy of the BillingResult to ensure it stays alive after the callback
290+
ProductDetailsResponseHandler?.Invoke(result.Clone(), queryResult?.ProductDetailsList);
260291
}
261292
}
262293

0 commit comments

Comments
 (0)