我有一个包含GLSurfaceView的Activity。当我按下后退按钮去上一个Activity时,它设法显示该Activity,但屏幕没有响应,最终会出现ANR。
这是onSurfaceCreated()代码:
- 编辑 -
如果我将mSurfaceView.onPause();
移动到所有者片段的onPause()
,那么应用程序在退出片段后不会冻结,但它通常会无声地崩溃(没有力量)在退出片段后几秒钟。
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
if (mOpenGlesVersion == OPENGLES_VERSION_10) mOpenGles = new OpenGles10();
else if (mOpenGlesVersion == OPENGLES_VERSION_11) mOpenGles = new OpenGles11();
else if (mOpenGlesVersion == OPENGLES_VERSION_20) mOpenGles = new OpenGles20();
// Let the caller know the surface has been created.
if (mListener != null) mListener.onGLSurfaceViewCreated();
// No intention of drawing anything, just gathering info.
mSurfaceView.onPause();
}
这是从/data/anr/traces.txt获取的日志信息: (由于--MORE - 有两行被弄乱了)
DALVIK THREADS:
(mutexes: tll=0 tsl=0 tscl=0 ghl=0 hwl=0 hwll=0)
"main" prio=5 tid=1 WAIT
| group="main" sCount=1 dsCount=0 obj=0x4001f188 self=0xce60
| sysTid=22603 nice=0 sched=0/0 cgrp=default handle=-1345006528
| schedstat=( 9586303756 3122772189 8867 )
at java.lang.Object.wait(Native Method)
- waiting on <0x405b3a70> (a android.opengl.GLSurfaceView$GLThreadManager)
at java.lang.Object.wait(Object.java:358)
at android.opengl.GLSurfaceView$GLThread.surfaceDestroyed(GLSurfaceView.java:1446)
at android.opengl.GLSurfaceView.surfaceDestroyed(GLSurfaceView.java:483)
at android.view.SurfaceView.reportSurfaceDestroyed(SurfaceView.java:587)
at android.view.SurfaceView.updateWindow(SurfaceView.java:481)
at android.view.SurfaceView.onWindowVisibilityChanged(SurfaceView.java:213)
at android.view.View.dispatchDetachedFromWindow(View.java:6186)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1162)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1162)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:1162)
at android.view.ViewGroup.removeViewInternal(ViewGroup.java:2201)
at android.view.ViewGroup.removeViewInternal(ViewGroup.java:2187)
at android.view.ViewGroup.removeView(ViewGroup.java:2135)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:998)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
at android.support.v4.app.FragmentManagerImpl.dispatchDestroy(FragmentManager.java:1843)
at android.support.v4.app.FragmentActivity.onDestroy(FragmentActivity.java:314)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:2780)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:2811)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:2927)
at android.app.ActivityThread.access$1600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3835)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
at dalvik.system.NativeStart.main(Native Method)
"GLThread 15" prio=5 tid=14 WAIT
| group="main" sCount=1 dsCount=0 obj=0x405634c0 self=0x200700
| sysTid=22637 nice=0 sched=0/0 cgrp=default handle=2099256
| schedstat=( 52276621 103881831 88 )
at java.lang.Object.wait(Native Method)
- waiting on <0x405b3a70> (a android.opengl.GLSurfaceView$GLThreadManager)
at java.lang.Object.wait(Object.java:358)
at android.opengl.GLSurfaceView$GLThread.onPause(GLSurfaceView.java:1466)
at android.opengl.GLSurfaceView.onPause(GLSurfaceView.java:501)
at com.jphilli85.deviceinfo.unit.Graphics.onSurfaceCreated(Graphics.java:237)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1348)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)
"ModernAsyncTask #3" prio=5 tid=13 WAIT
| group="main" sCount=1 dsCount=0 obj=0x40542210 self=0x1dc970
| sysTid=22620 nice=10 sched=0/0 cgrp=bg_non_interactive handle=2201640
| schedstat=( 6530762 28076172 5 )
at java.lang.Object.wait(Native Method)
- waiting on <0x4050bba8> (a java.lang.VMThread)
at java.lang.Thread.parkFor(Thread.java:1424)
at java.lang.LangAccessImpl.parkFor(LangAccessImpl.java:48)
at sun.misc.Unsafe.park(Unsafe.java:337)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:157)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2016)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:411)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1021)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1081)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
at java.lang.Thread.run(Thread.java:1019)
"java.lang.ProcessManager" daemon prio=5 tid=12 WAIT
| group="main" sCount=1 dsCount=0 obj=0x40542680 self=0x17a100
| sysTid=22614 nice=0 sched=0/0 cgrp=default handle=1968864
| schedstat=( 1342773 5157472 8 )
at java.lang.Object.wait(Native Method)
- waiting on <0x405424e8> (a java.util.HashMap)
at java.lang.Object.wait(Object.java:358)
at java.lang.ProcessManager.onExit(ProcessManager.java:139)
at java.lang.ProcessManager.watchChildren(Native Method)
at java.lang.ProcessManager$1.run(ProcessManager.java:85)
"ModernAsyncTask #2" prio=5 tid=11 WAIT
| group="main" sCount=1 dsCount=0 obj=0x4050d3d0 self=0x1dc030
| sysTid=22613 nice=10 sched=0/0 cgrp=bg_non_interactive handle=1948768
| schedstat=( 4455566 78338624 12 )
at java.lang.Object.wait(Native Method)
- waiting on <0x4050dea8> (a java.lang.VMThread)
at java.lang.Thread.parkFor(Thread.java:1424)
at java.lang.LangAccessImpl.parkFor(LangAccessImpl.java:48)
at sun.misc.Unsafe.park(Unsafe.java:337)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:157)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2016)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:411)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1021)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1081)
581) .util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:
at java.lang.Thread.run(Thread.java:1019)
"Binder Thread #3" prio=5 tid=10 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x40539b60 self=0x16cf48
| sysTid=22612 nice=0 sched=0/0 cgrp=default handle=1494488
| schedstat=( 15869140 35827635 53 )
at dalvik.system.NativeStart.run(Native Method)
"ModernAsyncTask #1" prio=5 tid=9 WAIT
| group="main" sCount=1 dsCount=0 obj=0x40529180 self=0x169830
| sysTid=22611 nice=10 sched=0/0 cgrp=bg_non_interactive handle=1481064
| schedstat=( 10253907 86822509 28 )
at java.lang.Object.wait(Native Method)
- waiting on <0x40521600> (a java.lang.VMThread)
at java.lang.Thread.parkFor(Thread.java:1424)
at java.lang.LangAccessImpl.parkFor(LangAccessImpl.java:48)
at sun.misc.Unsafe.park(Unsafe.java:337)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:157)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2016)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:411)
1) .util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:102
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1081)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
at java.lang.Thread.run(Thread.java:1019)
"Binder Thread #2" prio=5 tid=8 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x40514410 self=0x95298
| sysTid=22610 nice=0 sched=0/0 cgrp=default handle=609832
| schedstat=( 15533441 34057622 53 )
at dalvik.system.NativeStart.run(Native Method)
"Binder Thread #1" prio=5 tid=7 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x405129d0 self=0x93c40
| sysTid=22609 nice=0 sched=0/0 cgrp=default handle=971896
| schedstat=( 16906736 43731688 68 )
at dalvik.system.NativeStart.run(Native Method)
"Compiler" daemon prio=5 tid=6 VMWAIT
| group="system" sCount=1 dsCount=0 obj=0x4050e240 self=0x93240
| sysTid=22608 nice=0 sched=0/0 cgrp=default handle=972152
| schedstat=( 354705825 99243166 2500 )
at dalvik.system.NativeStart.run(Native Method)
"JDWP" daemon prio=5 tid=5 VMWAIT
| group="system" sCount=1 dsCount=0 obj=0x4050e190 self=0x92900
| sysTid=22607 nice=0 sched=0/0 cgrp=default handle=974088
| schedstat=( 3662110 8544920 16 )
at dalvik.system.NativeStart.run(Native Method)
"Signal Catcher" daemon prio=5 tid=4 RUNNABLE
| group="system" sCount=0 dsCount=0 obj=0x4050e0d0 self=0xedb78
| sysTid=22606 nice=0 sched=0/0 cgrp=default handle=972784
| schedstat=( 2044677 305177 6 )
at dalvik.system.NativeStart.run(Native Method)
"GC" daemon prio=5 tid=3 VMWAIT
| group="system" sCount=1 dsCount=0 obj=0x4050e028 self=0xed9e0
| sysTid=22605 nice=0 sched=0/0 cgrp=default handle=526152
| schedstat=( 59478766 61553948 32 )
at dalvik.system.NativeStart.run(Native Method)
"HeapWorker" daemon prio=5 tid=2 VMWAIT
| group="system" sCount=1 dsCount=0 obj=0x4050df70 self=0xed878
| sysTid=22604 nice=0 sched=0/0 cgrp=default handle=965360
| schedstat=( 38177485 36834717 39 )
at dalvik.system.NativeStart.run(Native Method)
答案 0 :(得分:1)
"GLThread 15" prio=5 tid=14 WAIT
| group="main" sCount=1 dsCount=0 obj=0x405634c0 self=0x200700
| sysTid=22637 nice=0 sched=0/0 cgrp=default handle=2099256
| schedstat=( 52276621 103881831 88 )
at java.lang.Object.wait(Native Method)
- waiting on <0x405b3a70> (a android.opengl.GLSurfaceView$GLThreadManager)
at java.lang.Object.wait(Object.java:358)
at android.opengl.GLSurfaceView$GLThread.onPause(GLSurfaceView.java:1466)
at android.opengl.GLSurfaceView.onPause(GLSurfaceView.java:501)
at com.jphilli85.deviceinfo.unit.Graphics.onSurfaceCreated(Graphics.java:237)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1348)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)
您的Graphics.onSurfaceCreated()
已调用GLSurfaceView.onPause()
。你不应该调用onPause
或者你遇到死锁。 onPause()
将调用wait()
,您的surfaceDestroyed()
将调用wait()
。
答案 1 :(得分:1)