下面列出了android.support.v4.app.Fragment#onResume ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void updateRoomListIfNeeded() {
try {
for (Fragment f : G.fragmentManager.getFragments()) {
if (f == null) {
continue;
}
if (f instanceof FragmentMain || f instanceof FragmentCall) {
f.onResume();
}
}
} catch (Exception e) {
HelperLog.setErrorLog("fragment setting updateRoomListIfNeeded " + e.toString());
}
}
public void showFragment(String tag, boolean onresume) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
Fragment fragment = getSupportFragmentManager().findFragmentByTag(tag);
if (fragment == null) {
if (App.getInstance().getTabByTag(tag) != null) {
TabItem tabItem = App.getInstance().getTabByTag(tag);
addTab(tabItem.getTitle(), tabItem.getUrl(), tabItem.getFragment());
return;
}
transaction.commitAllowingStateLoss();
return;
}
if (onresume) fragment.onResume();
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).show(fragment);
transaction.commitAllowingStateLoss();
}
/**
* A way to notify fragments when they become visible to user in this pager
*/
@Override
public void setPrimaryItem(ViewGroup container, int position, @NonNull Object object) {
Fragment newPrimary = (Fragment) object;
if(oldPrimary != newPrimary) {
if(oldPrimary != null) {
oldPrimary.setUserVisibleHint(false);
oldPrimary.onPause();
}
newPrimary.setUserVisibleHint(true);
newPrimary.onResume();
oldPrimary = newPrimary;
}
super.setPrimaryItem(container, position, object);
}
@Override
public void onPageSelected(int position) {
Fragment fragment = mSectionsPagerAdapter.getFragment(position);
if (fragment != null) {
fragment.onResume();
}
}
@Override
public void onCheckedChanged(RadioGroup radioGroup, int checkId) {
for (int i = 0; i < radioGroup.getChildCount(); i++) {
if (radioGroup.getChildAt(i).getId() == checkId) {
// 即将要展示的Fragment
Fragment target = mFragmentList.get(i);
Fragment currentFragment = getCurrentFragment();
currentFragment.onPause();
FragmentTransaction fragmentTransaction = getFragmentTransaction();
if (target.isAdded()) {
target.onResume();
fragmentTransaction.show(target).hide(currentFragment);
} else {
fragmentTransaction.add(mContentId, target).show(target).hide(currentFragment);
}
fragmentTransaction.commit();
currentTab = i;
if (mFragmentToogleListener != null) {
mFragmentToogleListener.onToogleChange(target, currentTab);
}
}
}
}
@Override
protected void onPostResume() {
super.onPostResume();
activityPaused = false;
if (App.getInstance().getCurrentFragmentTag() == null) {
BrickInfo brickInfo = ListCore.getRegisteredBrick(Preferences.Lists.getLastSelectedList());
if (brickInfo == null)
brickInfo = new NewsPagerBrickInfo();
selectItem(brickInfo);
}
if (tabOnIntent != null) {
addTabToList(tabOnIntent.getTitle(), tabOnIntent.getUrl(), tabOnIntent.getTag(), tabOnIntent.getFragment(), true);
}
if (tabTagForRemove != null) {
tryRemoveTab(tabTagForRemove, true);
}
tabTagForRemove = null;
tabOnIntent = null;
if (!(String.valueOf(App.getInstance().getCurrentFragmentTag())).equals("null")) {
Fragment fragment = getSupportFragmentManager().findFragmentByTag(App.getInstance().getCurrentFragmentTag());
if (fragment != null) {
fragment.onResume();
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
int[] ints = new int[2];
appBarLayout.getLocationOnScreen(ints);
if (statusBarHeight != ints[1] && ints[1] != 0)
setStatusBarHeight.run();
}
}
private void showFragment(FragmentTransaction transaction, String tag) {
Fragment fragment = getSupportFragmentManager().findFragmentByTag(tag);
fragment.onResume();
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).show(fragment);
}