Java Code Examples for android.app.fragmenttransaction#remove()

The following examples show how to use android.app.fragmenttransaction#remove() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocationOpenerBaseFragment.java    From edslite with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void detachTask()
{
    FragmentManager fm = getFragmentManager();
    if(fm!=null)
    {
        FragmentTransaction trans = fm.beginTransaction();
        trans.remove(this);
        LocationOpenerBaseFragment f = (LocationOpenerBaseFragment) fm.findFragmentByTag(getArguments().getString(ARG_OPENER_TAG));
        if(f!=null)
            trans.remove(f);
        trans.commitAllowingStateLoss();
        Logger.debug(String.format("TaskFragment %s has been removed from the fragment manager", this));
        onEvent(EventType.Removed, this);
    }
}
 
Example 2
Source File: VideoDetailActivity.java    From android-viewer-for-khan-academy with GNU General Public License v3.0 6 votes vote down vote up
private void createAndAttachCaptionFragment(int containerId) {
	FragmentTransaction tx = getFragmentManager().beginTransaction();
	
	if (captionFragment != null) {
		tx.remove(captionFragment);
	}
	
	captionFragment = new CaptionFragment();
	Bundle args = new Bundle();
	if (video != null) {
		args.putString(Constants.PARAM_VIDEO_ID, video.getId());
		if (videoFragment != null) {
			args.putInt(PARAM_VIDEO_POSITION, videoFragment.getVideoPosition());
		}
	}
	// Set args even if empty to avoid possible NPE inside CaptionFragment.
	captionFragment.setArguments(args);
	captionFragment.registerCallbacks(this);
	
	tx.replace(containerId, captionFragment);
	tx.commit();
	// Force execute, so we can populateHeader afterward.
	getFragmentManager().executePendingTransactions();
}
 
Example 3
Source File: FragmentDialog.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
void showDialog() {
    mStackLevel++;

    // DialogFragment.show() will take care of adding the fragment
    // in a transaction.  We also want to remove any currently showing
    // dialog, so make our own transaction and take care of that here.
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    Fragment prev = getFragmentManager().findFragmentByTag("dialog");
    if (prev != null) {
        ft.remove(prev);
    }
    ft.addToBackStack(null);

    // Create and show the dialog.
    DialogFragment newFragment = MyDialogFragment.newInstance(mStackLevel);
    newFragment.show(ft, "dialog");
}
 
Example 4
Source File: PrinterActivity.java    From Printer with Apache License 2.0 6 votes vote down vote up
private void showBluetoothTest() {
    int width;
    try {
        width = Integer.valueOf(edtWidth.getText().toString());
    } catch (Exception e) {
        width = 500;
    }
    String strQRCode = edtQRCode.getText().toString();
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    Fragment prev = getFragmentManager().findFragmentByTag(FRAGMENT_BLUETOOTH);
    if (prev != null) {
        ft.remove(prev);
    }
    ft.addToBackStack(null);
    BluetoothTestDialogFragment fragment = BluetoothTestDialogFragment
            .getFragment(type, width, height, strQRCode);
    fragment.show(ft, FRAGMENT_BLUETOOTH);
}
 
Example 5
Source File: MapsAppActivity.java    From maps-app-android with Apache License 2.0 6 votes vote down vote up
/**
 * Opens the map represented by the specified portal item or if null, opens
 * a default map.
 *
 * @param portalItemId
 *            - String representing a portal resource
 * @param basemapPortalItemId
 *            - String representing a basemap portal item
 */
public void showMap(String portalItemId, String basemapPortalItemId) {
	// remove existing MapFragment explicitly, simply replacing it can cause
	// the app to freeze when switching basemaps
	FragmentTransaction transaction;
	FragmentManager fragmentManager = getFragmentManager();
	Fragment currentMapFragment = fragmentManager.findFragmentByTag(MapFragment.TAG);
	if (currentMapFragment != null) {
		transaction = fragmentManager.beginTransaction();
		transaction.remove(currentMapFragment);
		transaction.commit();
	}

	MapFragment mapFragment = MapFragment.newInstance(portalItemId, basemapPortalItemId);

	transaction = fragmentManager.beginTransaction();
	transaction.replace(R.id.maps_app_activity_content_frame, mapFragment, MapFragment.TAG);
	transaction.addToBackStack(null);
	transaction.commit();

	invalidateOptionsMenu(); // reload the options menu
}
 
Example 6
Source File: Utils.java    From android-kernel-tweaker with GNU General Public License v3.0 5 votes vote down vote up
public static void showAbout(Activity activity) {

        FragmentManager fm = activity.getFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        Fragment prev = fm.findFragmentByTag("dialog_about");
        if (prev != null) {
            ft.remove(prev);
        }
        ft.addToBackStack(null);

        new AboutDialog().show(ft,"dialog_about");
    }
 
Example 7
Source File: BaseRestoreInstanceFragment.java    From Material-SearchView with Apache License 2.0 5 votes vote down vote up
public void show(@NonNull final FragmentManager manager) {
    FragmentTransaction transaction = manager.beginTransaction();
    Fragment prev = manager.findFragmentByTag(DIALOG_TAG);
    if (prev != null) {
        transaction.remove(prev);
    }

    transaction.add(this, DIALOG_TAG);
    transaction.commitAllowingStateLoss();
    manager.executePendingTransactions();
}
 
Example 8
Source File: ConversationsActivity.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
private void initializeFragments() {
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
    Fragment secondaryFragment = getFragmentManager().findFragmentById(R.id.secondary_fragment);
    if (mainFragment != null) {
        if (binding.secondaryFragment != null) {
            if (mainFragment instanceof ConversationFragment) {
                getFragmentManager().popBackStack();
                transaction.remove(mainFragment);
                transaction.commit();
                getFragmentManager().executePendingTransactions();
                transaction = getFragmentManager().beginTransaction();
                transaction.replace(R.id.secondary_fragment, mainFragment);
                transaction.replace(R.id.main_fragment, new ConversationsOverviewFragment());
                transaction.commit();
                return;
            }
        } else {
            if (secondaryFragment instanceof ConversationFragment) {
                transaction.remove(secondaryFragment);
                transaction.commit();
                getFragmentManager().executePendingTransactions();
                transaction = getFragmentManager().beginTransaction();
                transaction.replace(R.id.main_fragment, secondaryFragment);
                transaction.addToBackStack(null);
                transaction.commit();
                return;
            }
        }
    } else {
        transaction.replace(R.id.main_fragment, new ConversationsOverviewFragment());
    }
    if (binding.secondaryFragment != null && secondaryFragment == null) {
        transaction.replace(R.id.secondary_fragment, new ConversationFragment());
    }
    transaction.commit();
}
 
Example 9
Source File: ChangelogDialog.java    From turbo-editor with GNU General Public License v3.0 5 votes vote down vote up
public static void showChangeLogDialog(FragmentManager fragmentManager) {
    ChangelogDialog changelogDialog = new ChangelogDialog();
    FragmentTransaction ft = fragmentManager.beginTransaction();
    Fragment prev = fragmentManager.findFragmentByTag("changelogdemo_dialog");
    if (prev != null) {
        ft.remove(prev);
    }
    ft.addToBackStack(null);
    changelogDialog.show(ft, "changelogdemo_dialog");
}
 
Example 10
Source File: HelpUtils.java    From android-show-hide-toolbar with Apache License 2.0 5 votes vote down vote up
public static void showAbout(Activity activity) {
  FragmentManager fm = activity.getFragmentManager();
  FragmentTransaction ft = fm.beginTransaction();
  Fragment prev = fm.findFragmentByTag(ABOUT_DIALOG_TAG);
  if (prev != null) {
    ft.remove(prev);
  }
  ft.addToBackStack(null);

  new AboutDialog().show(ft, "about_dialog");
}
 
Example 11
Source File: MainActivity.java    From DaggerWorkshopGDG with Apache License 2.0 5 votes vote down vote up
@Override
protected void onSaveInstanceState(Bundle outState) {
    if (twoPanel) {
        FragmentTransaction fragmentTransaction = this.getFragmentManager().beginTransaction();
        Fragment detailFragment = getFragmentManager().findFragmentByTag(DETAIL_FRAGMENT);
        if (detailFragment != null) {
            fragmentTransaction.remove(detailFragment);
        }
        fragmentTransaction.commit();
    }

    super.onSaveInstanceState(outState);
}
 
Example 12
Source File: RNSensitiveInfoModule.java    From react-native-sensitive-info with MIT License 5 votes vote down vote up
private void showDialog(final HashMap strings, Object cryptoObject, FingerprintUiHelper.Callback callback) {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
        // DialogFragment.show() will take care of adding the fragment
        // in a transaction.  We also want to remove any currently showing
        // dialog, so make our own transaction and take care of that here.

        Activity activity = getCurrentActivity();
        if (activity == null) {
            callback.onError(AppConstants.E_INIT_FAILURE,
                    strings.containsKey("cancelled") ? strings.get("cancelled").toString() : "Authentication was cancelled");
            return;
        }

        FragmentTransaction ft = activity.getFragmentManager().beginTransaction();
        Fragment prev = getCurrentActivity().getFragmentManager().findFragmentByTag(AppConstants.DIALOG_FRAGMENT_TAG);
        if (prev != null) {
            ft.remove(prev);
        }
        ft.addToBackStack(null);

        // Create and show the dialog.
        FingerprintAuthenticationDialogFragment newFragment = FingerprintAuthenticationDialogFragment.newInstance(strings);
        newFragment.setCryptoObject((FingerprintManager.CryptoObject) cryptoObject);
        newFragment.setCallback(callback);
        newFragment.show(ft, AppConstants.DIALOG_FRAGMENT_TAG);
    }
}
 
Example 13
Source File: BaseFragmentUtil.java    From android-commons with Apache License 2.0 5 votes vote down vote up
public static void showDialogFragment(final DialogFragment dialog,
                                      final String tag, final FragmentManager fragmentManager) {
  final FragmentTransaction ft = fragmentManager.beginTransaction();
  final Fragment prev = fragmentManager.findFragmentByTag(tag);
  if (prev != null) {
    ft.remove(prev);
  }
  ft.add(dialog, tag);
  ft.commitAllowingStateLoss();
}
 
Example 14
Source File: HelpUtils.java    From BetterWeather with Apache License 2.0 5 votes vote down vote up
public static void showAboutDialog(Activity activity) {
    FragmentManager fm = activity.getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    Fragment prev = fm.findFragmentByTag("dialog_about");
    if (prev != null) {
        ft.remove(prev);
    }
    ft.addToBackStack(null);

    new AboutDialog().show(ft, "dialog_about");
}
 
Example 15
Source File: FragmentUtil.java    From SmallGdufe-Android with GNU General Public License v3.0 5 votes vote down vote up
/**清空所有带此tag的fragment*/
public void removeAll(String tag){
    FragmentTransaction ft = fm.beginTransaction();
    for (Fragment f:fs) {
        if(f.getTag().equals(tag))ft.remove(f);
    }
    ft.commitAllowingStateLoss();
}
 
Example 16
Source File: PlayerPageAdapter.java    From Android-Remote with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void destroyItem(ViewGroup viewPager, int position, Object object) {
    if (position >= getCount()) {
        FragmentManager manager = ((Fragment) object).getFragmentManager();
        FragmentTransaction trans = manager.beginTransaction();
        trans.remove((Fragment) object);
        trans.commit();
    }
}
 
Example 17
Source File: IntroductionActivity.java    From io2014-codelabs with Apache License 2.0 5 votes vote down vote up
private void goToFragment(String oldFragmentTag, String newFragmentTag, Fragment newFragment) {
    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    fragmentTransaction.add(R.id.intro_frame, newFragment, newFragmentTag);
    Fragment fragment = getFragmentManager().findFragmentByTag(oldFragmentTag);
    if (fragment != null) {
        fragmentTransaction.remove(getFragmentManager().findFragmentByTag(oldFragmentTag));
    }
    fragmentTransaction.commit();
}
 
Example 18
Source File: MainActivity.java    From remoteyourcam-usb with Apache License 2.0 4 votes vote down vote up
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
    ft.remove(fragment);
}
 
Example 19
Source File: ActionBarTabs.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
    ft.remove(mFragment);
}
 
Example 20
Source File: TabsListener.java    From android with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Se ha deseleccionado una pestaña. Se elimina de la pantalla
 */
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
	
	ft.remove(fragmento);
}