Java Code Examples for androidx.fragment.app.FragmentManager#putFragment()

The following examples show how to use androidx.fragment.app.FragmentManager#putFragment() . 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: MainActivity.java    From SkyTube with GNU General Public License v3.0 5 votes vote down vote up
private void putFragment(FragmentManager fragmentManager,  Bundle bundle, @NonNull String key,
					@NonNull Fragment fragment) {
	if (fragment.getFragmentManager() != fragmentManager) {
		Logger.e(MainActivity.this, "Error fragment has a different FragmentManager than expected: Fragment=" + fragment + ", manager=" + fragmentManager + ", Fragment.manager=" + fragment.getFragmentManager() + " for key=" + key);
	} else {
		fragmentManager.putFragment(bundle, key, fragment);
	}
}
 
Example 2
Source File: DateTimePickerDialog.java    From mage-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    outState.putSerializable(CALENDAR_INSTANCE, calendar);

    FragmentManager manager = getChildFragmentManager();
    manager.putFragment(outState, DatePickerFragment.class.getName(), datePickerFragment);
    manager.putFragment(outState, TimePickerFragment.class.getName(), timePickerFragment);
}
 
Example 3
Source File: AppcompatActivity.java    From ui with Apache License 2.0 5 votes vote down vote up
@Override protected void onSaveInstanceState(Bundle outState) {
	super.onSaveInstanceState(outState);


	FragmentManager fragmentManager = getSupportFragmentManager();
	fragmentManager.putFragment(outState, "ONE", one);
	fragmentManager.putFragment(outState,"TWO", two);
	fragmentManager.putFragment(outState,"THREE", three);
	fragmentManager.putFragment(outState,"FOUR", four);
	fragmentManager.putFragment(outState,"FIVE", five);

}
 
Example 4
Source File: MainActivity.java    From syncthing-android with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Saves current tab index and fragment states.
 */
@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    FragmentManager fm = getSupportFragmentManager();
    Consumer<Fragment> putFragment = fragment -> {
        if (fragment != null && fragment.isAdded()) {
            fm.putFragment(outState, fragment.getClass().getName(), fragment);
        }
    };
    putFragment.accept(mFolderListFragment);
    putFragment.accept(mDeviceListFragment);
    putFragment.accept(mDrawerFragment);

    outState.putInt("currentTab", mViewPager.getCurrentItem());
    outState.putBoolean(BATTERY_DIALOG_DISMISSED, mBatteryOptimizationsDialog == null || !mBatteryOptimizationsDialog.isShowing());
    outState.putBoolean(IS_SHOWING_RESTART_DIALOG, mRestartDialog != null && mRestartDialog.isShowing());
    if(mQrCodeDialog != null && mQrCodeDialog.isShowing()) {
        outState.putBoolean(IS_QRCODE_DIALOG_DISPLAYED, true);
        ImageView qrCode = mQrCodeDialog.findViewById(R.id.qrcode_image_view);
        TextView deviceID = mQrCodeDialog.findViewById(R.id.device_id);
        outState.putParcelable(QRCODE_BITMAP_KEY, ((BitmapDrawable) qrCode.getDrawable()).getBitmap());
        outState.putString(DEVICEID_KEY, deviceID.getText().toString());
    }
    Util.dismissDialogSafe(mRestartDialog, this);
}