[Android] Fix Bug: java.lang.IllegalStateException:Fragment not attached to Activity
再切換Fragment時,調用getResource()導致異常問題 java.lang.IllegalStateException:Fragment not attached to Activity
解決方法:
getResource()時,加入isAdded()去判斷Fragment is attached to Activity
if (isAdded()) {
mSurfaceView = (SurfaceView) view.findViewById(R.id.surfaceView);
}
相關解決方法參考:
1. https://stackoverflow.com/questions/36745309/accessing-resources-in-fragment-background-task-returns-illegalstateexception-of
留言
張貼留言