InApp 购买时出错 android.app.ServiceConnectionLeaked
Error android.app.ServiceConnectionLeaked when InApp purchase
我正在使用 Xamarin Android 开发一个 Android 应用程序。
我正在使用 James Montemagno 的 InAppBilling 插件。
当我调用 PurchaseAsync 方法时,PlayStore 对话框打开。但是在后台我的应用程序冻结并且我没有得到任何结果。
var purchase = await CrossInAppBilling.Current.PurchaseAsync(productId, ItemType.Subscription, "apppayload");
在系统日志中有一个 android.app.ServiceConnectionLeaked 错误:
02-17 22:13:05.434 LENOVO YT3-X50L Error 8031 ActivityThread android.app.ServiceConnectionLeaked: Activity md5742c3bd4cdfedb6330d25c53207d662c.ShopActivity has leaked ServiceConnection md57a6f08dbc6561d468b2675b2ac9edab2.InAppBillingImplementation_InAppBillingServiceConnection@2277a40 that was originally bound here
at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:1092)
at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:986)
at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1303)
at android.app.ContextImpl.bindService(ContextImpl.java:1286)
at android.content.ContextWrapper.bindService(ContextWrapper.java:604)
at mono.android.view.View_OnClickListenerImplementor.n_onClick(Native Method)
at mono.android.view.View_OnClickListenerImplementor.onClick(View_OnClickListenerImplementor.java:30)
at android.view.View.performClick(View.java:5205)
at android.view.View$PerformClick.run(View.java:21164)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
我只在 LENOVO YT3-X50L 上遇到这个错误。在三星手机上它工作正常...
ServiceConnectionLeaked
CrossInAppBilling
代码没有考虑到您的 Activity 可以 killed/flushed 由于内存 pressure/requirements 而从内存中获取,并且没有直接做任何尝试阻止它,由应用程序开发人员决定何时需要采取特殊措施。
这是我在 lower-end Android 设备和新的 Android Oreo Go (<=1MB) 测试设备中看到的很多东西,但可以在任何设备上发生, 但在 2GB 及更低容量的设备上最明显。
在调用任何外部代码之前flush/release尽可能多的内存
专注于释放图像通常是减少内存的最大回报(购买完成后恢复它们)
对于 Oreo Go 512MB 设备,我不得不加倍努力并完成当前 Activity,创建一个新的 blank/empty 瞬态 Activity然后调用外部代码(应用计费、相机等),完成后,恢复原始 activity 并使用外部获得的新信息更新它。
注意:首先分析您的应用和 activity 以便集中时间。
使用您自己的 Keep-Alive 服务
- 使用 Start/StopService 而不是 Bind/UnBindService
- 使其成为前台服务
注意:这不会阻止 OS 来自 killing/flushing 你的 Activities/Services,它只是提供了一个 "hint" 它不应该...
注意:监控 RunningAppProcessInfo
中的 Importance
状态以确定您的应用程序是否在执行外部代码之前进入 ReasonServiceInUse
。
我正在使用 Xamarin Android 开发一个 Android 应用程序。 我正在使用 James Montemagno 的 InAppBilling 插件。
当我调用 PurchaseAsync 方法时,PlayStore 对话框打开。但是在后台我的应用程序冻结并且我没有得到任何结果。
var purchase = await CrossInAppBilling.Current.PurchaseAsync(productId, ItemType.Subscription, "apppayload");
在系统日志中有一个 android.app.ServiceConnectionLeaked 错误:
02-17 22:13:05.434 LENOVO YT3-X50L Error 8031 ActivityThread android.app.ServiceConnectionLeaked: Activity md5742c3bd4cdfedb6330d25c53207d662c.ShopActivity has leaked ServiceConnection md57a6f08dbc6561d468b2675b2ac9edab2.InAppBillingImplementation_InAppBillingServiceConnection@2277a40 that was originally bound here
at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:1092)
at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:986)
at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1303)
at android.app.ContextImpl.bindService(ContextImpl.java:1286)
at android.content.ContextWrapper.bindService(ContextWrapper.java:604)
at mono.android.view.View_OnClickListenerImplementor.n_onClick(Native Method)
at mono.android.view.View_OnClickListenerImplementor.onClick(View_OnClickListenerImplementor.java:30)
at android.view.View.performClick(View.java:5205)
at android.view.View$PerformClick.run(View.java:21164)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
我只在 LENOVO YT3-X50L 上遇到这个错误。在三星手机上它工作正常...
ServiceConnectionLeaked
CrossInAppBilling
代码没有考虑到您的 Activity 可以 killed/flushed 由于内存 pressure/requirements 而从内存中获取,并且没有直接做任何尝试阻止它,由应用程序开发人员决定何时需要采取特殊措施。
这是我在 lower-end Android 设备和新的 Android Oreo Go (<=1MB) 测试设备中看到的很多东西,但可以在任何设备上发生, 但在 2GB 及更低容量的设备上最明显。
在调用任何外部代码之前flush/release尽可能多的内存
专注于释放图像通常是减少内存的最大回报(购买完成后恢复它们)
对于 Oreo Go 512MB 设备,我不得不加倍努力并完成当前 Activity,创建一个新的 blank/empty 瞬态 Activity然后调用外部代码(应用计费、相机等),完成后,恢复原始 activity 并使用外部获得的新信息更新它。
注意:首先分析您的应用和 activity 以便集中时间。
使用您自己的 Keep-Alive 服务
- 使用 Start/StopService 而不是 Bind/UnBindService
- 使其成为前台服务
注意:这不会阻止 OS 来自 killing/flushing 你的 Activities/Services,它只是提供了一个 "hint" 它不应该...
注意:监控 RunningAppProcessInfo
中的 Importance
状态以确定您的应用程序是否在执行外部代码之前进入 ReasonServiceInUse
。