游戏在接入时遇见了一个比较奇怪的问题,取消支付时返回游戏显示的是欢迎页面
查看log信息时,发现在点击支付时抛出了以下的错误信息:
02-23 15:55:46.511 32387-32387/? E/ActivityThread: Activity com.mfp.jellyblast.AppActivity has leaked IntentReceiver com.nearme.game.sdk.component.PayResultReceiver@3269740 that was originally registered here. Are you missing a call to unregisterReceiver()?
android.app.IntentReceiverLeaked: Activity com.mfp.jellyblast.AppActivity has leaked IntentReceiver com.nearme.game.sdk.component.PayResultReceiver@3269740 that was originally registered here. Are you missing a call to unregisterReceiver()?at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:920)
at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:721)
at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1182)
at android.app.ContextImpl.registerReceiver(ContextImpl.java:1162)
at android.app.ContextImpl.registerReceiver(ContextImpl.java:1156)
at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:564)
at com.nearme.game.sdk.b$3.onSuccess(GCInternalImpl.java:196)
at com.nearme.game.sdk.a$8.handleMessage(GCInternal.java:446)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5458)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
看了半天没想出是哪的错误,最后通过查看录屏时发现,原来在支付时activity发生了旋转,导致activity重新生成了,这也就解释了为什么会显示欢迎页面(ps:欢迎页面是在activity当中添加的)。解决方法是在activity声明中添加android:configChanges="keyboardHidden|orientation|screenSize",关于configChanges的说明参看http://blog.csdn.net/akiyame/article/details/44923335。
对android:configChanges属性,一般认为有以下几点:
1、不设置Activity的android:configChanges时,切屏会重新调用各个生命周期,切横屏时会执行一次,切竖屏时会执行两次
2、设置Activity的android:configChanges="orientation"时,切屏还是会重新调用各个生命周期,切横、竖屏时只会执行一次
3、设置Activity的android:configChanges="orientation|keyboardHidden"时,切屏不会重新调用各个生命周期,只会执行onConfigurationChanged方法
但是,自从Android 3.2(API 13),在设置Activity的android:configChanges="orientation|keyboardHidden"后,还是一样 会重新调用各个生命周期的。因为screen size也开始跟着设备的横竖切换而改变。所以,在AndroidManifest.xml里设置的MiniSdkVersion和 TargetSdkVersion属性大于等于13的情况下,如果你想阻止程序在运行时重新加载Activity,除了设置"orientation", 你还必须设置"ScreenSize"。
解决方法:
AndroidManifest.xml中设置android:configChanges="orientation|screenSize“