我在调用SoundPool.release()时收到以下ANR。这不是一致的缺陷,而是随机发生的。因此复制它有点费时。有两种方法可以解决它,AsyncTask或Thread。我不认为我可以在这里使用Handler,因为发布不应该在UIThread上运行。
DALVIK THREADS:
(mutexes: tll=0 tsl=0 tscl=0 ghl=0 hwl=0 hwll=0)
"main" prio=5 tid=1 NATIVE
| group="main" sCount=1 dsCount=0 obj=0x400281b8 self=0xd088
| sysTid=3623 nice=0 sched=0/0 cgrp=default handle=-1345006464
| schedstat=( 22209377936 9072495824 21774 )
at android.media.SoundPool.release(Native Method)
我已经使用Thread
修复了它public SoundManager() {
releaseRunnable = new Runnable() {
@Override
public void run() {
synchronized (releaseRunnable) {
mSoundPool.release();
mSoundPool = null;
}
}
};
releaseThread = new Thread(releaseRunnable);
}
public void release() {
if (mSoundPool != null) {
releaseThread.start();
}
}
我做得对吗?