我正在用Xamarin Android开发一个Android应用程序。
我正在使用james montemagno的inappbilling插件。
当我调用purchaseasync方法时,playstore对话框打开。但在后台我的应用程序冻结,我没有得到任何结果。
var purchase = await CrossInAppBilling.Current.PurchaseAsync(productId, ItemType.Subscription, "apppayload");
在sys日志中有一个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)
我只在联想YT3-X50L上发现这个错误。在三星手机上它工作正常…
最佳答案
服务连接中断CrossInAppBilling
代码没有考虑到由于内存压力/需求,您的活动可能会被终止/从内存中刷新,也没有直接采取任何措施试图阻止它,而是由应用程序开发人员决定何时需要采取特殊操作。
这是我在低端Android设备和新的Android Oreo Go(在调用任何外部代码之前,请刷新/释放尽可能多的内存
专注于发布图片通常是减少内存的最大回报(在购买完成后恢复图片)
在Oreo Go 512MB设备的情况下,我必须多走一步,完成当前活动,创建一个新的空白/空的临时活动,然后调用外部代码(应用程序计费、摄像头等),完成后,恢复原始活动,并将其与外部获得的新信息一起更新。
注意:请先分析你的应用程序和活动,以便集中你的时间。
使用你自己的生存服务
使用start/stopservice而不是bind/unbindservice
使其成为前台服务
注意:这并不能阻止操作系统杀死/刷新您的活动/服务,它只是提供了一个“提示”它不应该…
注意:在执行外部代码之前,监视Importance
中的RunningAppProcessInfo
状态,以确定您的应用是否正在进入ReasonServiceInUse
状态。