Activity下使用Viewpager + Fragment; 判斷fragment的顯示情況
阿新 • • 發佈:2018-12-19
@Override public void setUserVisibleHint(boolean isVisibleToUser) { super.setUserVisibleHint(isVisibleToUser); if (isVisibleToUser && isResumed()) { Log.d("CXL", "setUserVisibleHint: 1111" + type); onResume(); Log.d("CXL", "setUserVisibleHint: 2222" + type); } else if (!isVisibleToUser) { onPause(); Log.d("CXL", "setUserVisibleHint: unVisible" + type); } // if (getUserVisibleHint()) { //// onVisible(); // Log.d("CXL", "setUserVisibleHint: true" + type); // } else { //// onInvisible(); // Log.d("CXL", "setUserVisibleHint: false" + type); // } } @Override public void onResume() { super.onResume(); Log.d("CXL", "onResume: type" + type); if (getUserVisibleHint()) { Log.d("CXL", "onResume: " + type); DeliveryListActivity.POST_STATE = type; } }
Fragment:
Log資訊: