启动Activity,点击,然后快速点击back键,偶有ANR

做了一个Android项目,通过以下步骤:
1.启动Activit
2.快速点击几次屏幕
3.同时快速点击back key

我的项目里面点击屏幕会有声音出现,调用的是playEffect api;

一定几率会出现ANR现象。
一部分trace如下:

JNI: CheckJNI is off; workarounds are off; pins=0; globals=289

DALVIK THREADS:
(mutexes: tll=0 tsl=0 tscl=0 ghl=0)

“main” prio=5 tid=1 WAIT
| group=“main” sCount=1 dsCount=0 obj=0x41957de0 self=0x41946878
| sysTid=6095 nice=0 sched=0/0 cgrp=apps handle=1074524548
| state=S schedstat=( 2237425267 2628791289 8138 ) utm=161 stm=62 core=1
at java.lang.Object.wait(Native Method)

  • waiting on <0x422a59f8> (a android.opengl.GLSurfaceView$GLThreadManager)
    at java.lang.Object.wait(Object.java:361)
    at android.opengl.GLSurfaceView$GLThread.surfaceDestroyed(GLSurfaceView.java:1682)
    at android.opengl.GLSurfaceView.surfaceDestroyed(GLSurfaceView.java:553)
    at android.view.SurfaceView.updateWindow(SurfaceView.java:619)
    at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:254)
    at android.view.View.dispatchWindowVisibilityChanged(View.java:8096)
    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1110)
    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1110)
    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1110)
    at android.view.ViewGroup.dispatchWindowVisibilityChanged(ViewGroup.java:1110)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1464)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1208)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6277)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:788)
    at android.view.Choreographer.doCallbacks(Choreographer.java:591)
    at android.view.Choreographer.doFrame(Choreographer.java:560)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:774)
    at android.os.Handler.handleCallback(Handler.java:808)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:5299)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
    at dalvik.system.NativeStart.main(Native Method)

“GLThread 182” prio=5 tid=15 WAIT
| group=“main” sCount=1 dsCount=0 obj=0x42311788 self=0x55b34a08
| sysTid=6224 nice=0 sched=0/0 cgrp=apps handle=1437928992
| state=S schedstat=( 645040662 542080033 1474 ) utm=59 stm=5 core=1
at java.lang.Object.wait(Native Method)

  • waiting on <0x423118f0> (a java.lang.VMThread) held by tid=15 (GLThread 182)
    at java.lang.Thread.parkFor(Thread.java:1212)
    at sun.misc.Unsafe.park(Unsafe.java:325)
    at java.util.concurrent.locks.LockSupport.park(LockSupport.java:157)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:813)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly(AbstractQueuedSynchronizer.java:973)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1281)
    at java.util.concurrent.Semaphore.acquire(Semaphore.java:283)
    at org.cocos2dx.lib.Cocos2dxSound.playEffect(Cocos2dxSound.java:171)
    at org.cocos2dx.lib.Cocos2dxHelper.playEffect(Cocos2dxHelper.java:211)
    at org.cocos2dx.lib.Cocos2dxRenderer.nativeRender(Native Method)
    at org.cocos2dx.lib.Cocos2dxRenderer.onDrawFrame(Cocos2dxRenderer.java:97)
    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1557)
    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1263)

“Binder_4” prio=5 tid=19 NATIVE
| group=“main” sCount=1 dsCount=0 obj=0x4237c158 self=0x55b1ee20
| sysTid=6189 nice=0 sched=0/0 cgrp=apps handle=1437646232
| state=S schedstat=( 11442619 39364692 93 ) utm=1 stm=0 core=1
#00 pc 00024798 /system/lib/libc.so (__ioctl+8)
#01 pc 00038210 /system/lib/libc.so (ioctl+28)
#02 pc 0001d331 /system/lib/libbinder.so (android::IPCThreadState::talkWithDriver(bool)+140)
#03 pc 0001da6b /system/lib/libbinder.so (android::IPCThreadState::getAndExecuteCommand()+6)
#04 pc 0001db01 /system/lib/libbinder.so (android::IPCThreadState::joinThreadPool(bool)+48)
#05 pc 000219b5 /system/lib/libbinder.so
#06 pc 0000ea01 /system/lib/libutils.so (android::thread::_threadLoop(void*)+216)
#07 pc 0004f0dd /system/lib/libandroid_runtime.so (android::AndroidRuntime::javaThreadShell(void*)+68)
#08 pc 0000e533 /system/lib/libutils.so
#09 pc 0000d5b0 /system/lib/libc.so (__thread_entry+72)
at dalvik.system.NativeStart.run(Native Method)

“Voice_Controller” prio=5 tid=16 NATIVE
| group=“main” sCount=1 dsCount=0 obj=0x422b5948 self=0x55005008
| sysTid=6143 nice=0 sched=0/0 cgrp=apps handle=1426084960
| state=S schedstat=( 16211303 28510382 126 ) utm=1 stm=0 core=0
#00 pc 0002594c /system/lib/libc.so (epoll_wait+12)
#01 pc 000105e3 /system/lib/libutils.so (android::Looper::pollInner(int)+94)
#02 pc 00010811 /system/lib/libutils.so (android::Looper::pollOnce(int, int*, int*, void**)+92)
#03 pc 0006c955 /system/lib/libandroid_runtime.so (android::NativeMessageQueue::pollOnce(_JNIEnv*, int)+22)
#04 pc 0001e94c /system/lib/libdvm.so (dvmPlatformInvoke+112)
#05 pc 0004fcb9 /system/lib/libdvm.so (dvmCallJNIMethod(unsigned int const*, JValue*, Method const*, Thread*)+484)
#06 pc 00027d28 /system/lib/libdvm.so
#07 pc 0002f330 /system/lib/libdvm.so (dvmMterpStd(Thread*)+76)
#08 pc 0002c814 /system/lib/libdvm.so (dvmInterpret(Thread*, Method const*, JValue*)+188)
#09 pc 00063075 /system/lib/libdvm.so (dvmCallMethodV(Thread*, Method const*, Object*, bool, JValue*, std::__va_list)+340)
#10 pc 00063099 /system/lib/libdvm.so (dvmCallMethod(Thread*, Method const*, Object*, JValue*, …)+20)
#11 pc 00057731 /system/lib/libdvm.so
#12 pc 0000d5b0 /system/lib/libc.so (__thread_entry+72)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:138)
at android.os.Looper.loop(Looper.java:150)
at android.os.HandlerThread.run(HandlerThread.java:61)

这是什么原因呢?大神出来指点我一下可以么

应该是你启动时,底层在绘制加载界面,然后你点击屏幕,调用声音的接口又点击android返回键调用系统功能,此时主线程和绘制界面的opengl线程被阻塞住了进入了等待状态,所以才会出现未响应的问题,可以将放声音和允许android返回键点击放在场景加载完毕的方法里面写(onEnterTransitionDidFinish)

谢谢你的方法。