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

The following examples show how to use androidx.fragment.app.FragmentManager#popBackStack() . 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: FragmentHelper.java    From AndroidNavigation with MIT License 6 votes vote down vote up
public static void handleDismissFragment(@NonNull AwesomeFragment target, @NonNull AwesomeFragment presented, @Nullable AwesomeFragment top) {
    FragmentManager fragmentManager = target.requireFragmentManager();
    target.setAnimation(PresentAnimation.Modal);

    if (top == null) {
        top = (AwesomeFragment) fragmentManager.findFragmentById(target.getContainerId());
    }

    if (top == null) {
        return;
    }

    top.setAnimation(PresentAnimation.Modal);
    fragmentManager.beginTransaction().setMaxLifecycle(presented, Lifecycle.State.STARTED).commit();
    fragmentManager.popBackStack(presented.getSceneId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
    FragmentHelper.executePendingTransactionsSafe(fragmentManager);
    target.onFragmentResult(top.getRequestCode(), top.getResultCode(), top.getResultData());
}
 
Example 2
Source File: OpenChannelActivity.java    From SendBird-Android with MIT License 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_open_channel);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_open_channel);
    setSupportActionBar(toolbar);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_arrow_left_white_24_dp);
    }

    if (savedInstanceState == null) {
        // Load list of Open Channels
        Fragment fragment = OpenChannelListFragment.newInstance();

        FragmentManager manager = getSupportFragmentManager();
        manager.popBackStack();

        manager.beginTransaction()
                .replace(R.id.container_open_channel, fragment)
                .commit();
    }
}
 
Example 3
Source File: ContactSelectionActivity.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void addFragment(FragmentActivity fragmentActivity, Fragment fragmentToAdd,
                               String fragmentTag) {
    FragmentManager supportFragmentManager = fragmentActivity.getSupportFragmentManager();

    FragmentTransaction fragmentTransaction = supportFragmentManager
            .beginTransaction();
    fragmentTransaction.replace(R.id.layout_child_activity, fragmentToAdd,
            fragmentTag);

    if (supportFragmentManager.getBackStackEntryCount() > 1) {
        supportFragmentManager.popBackStack();
    }
    fragmentTransaction.addToBackStack(fragmentTag);
    fragmentTransaction.commitAllowingStateLoss();
    supportFragmentManager.executePendingTransactions();
}
 
Example 4
Source File: BackPressEventDispatchHelper.java    From XposedSmsCode with GNU General Public License v3.0 6 votes vote down vote up
public static boolean dispatchBackPressedEvent(FragmentManager fragmentManager) {
    List<Fragment> fragments = fragmentManager.getFragments();

    if (fragments == null)
        return false;

    for (int i = fragments.size() - 1; i >= 0; i--) {
        Fragment fragment = fragments.get(i);

        if (isBackPressedIntercepted(fragment)) {
            ((BackPressedListener) fragment).onBackPressed();
            return true;
        }
    }

    if (fragmentManager.getBackStackEntryCount() > 0) {
        fragmentManager.popBackStack();
        return true;
    }
    return false;
}
 
Example 5
Source File: NavigationFragment.java    From AndroidNavigation with MIT License 6 votes vote down vote up
private void popToFragmentInternal(AwesomeFragment fragment, boolean animated) {
    FragmentManager fragmentManager = getChildFragmentManager();

    AwesomeFragment topFragment = getTopFragment();
    if (topFragment == null || topFragment == fragment) {
        return;
    }

    fragmentManager.beginTransaction().setMaxLifecycle(topFragment, Lifecycle.State.STARTED).commit();

    topFragment.setAnimation(animated ? PresentAnimation.Push : PresentAnimation.None);
    fragment.setAnimation(animated ? PresentAnimation.Push : PresentAnimation.None);
    fragmentManager.popBackStack(fragment.getSceneId(), 0);

    fragmentManager.beginTransaction().setMaxLifecycle(fragment, Lifecycle.State.RESUMED).commit();

    FragmentHelper.executePendingTransactionsSafe(fragmentManager);
    fragment.onFragmentResult(topFragment.getRequestCode(), topFragment.getResultCode(), topFragment.getResultData());
}
 
Example 6
Source File: BackPressEventDispatchHelper.java    From SmsCode with GNU General Public License v3.0 6 votes vote down vote up
public static boolean dispatchBackPressedEvent(FragmentManager fragmentManager) {
    List<Fragment> fragments = fragmentManager.getFragments();

    if (fragments == null)
        return false;

    for (int i = fragments.size() - 1; i >= 0; i--) {
        Fragment fragment = fragments.get(i);

        if (isBackPressedIntercepted(fragment)) {
            ((BackPressedListener) fragment).onBackPressed();
            return true;
        }
    }

    if (fragmentManager.getBackStackEntryCount() > 0) {
        fragmentManager.popBackStack();
        return true;
    }
    return false;
}
 
Example 7
Source File: MainActivity.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void addFragment(FragmentActivity fragmentActivity, Fragment fragmentToAdd, String fragmentTag) {

        FragmentManager supportFragmentManager = fragmentActivity.getSupportFragmentManager();

        //Fragment activeFragment = UIService.getActiveFragment(fragmentActivity);
        FragmentTransaction fragmentTransaction = supportFragmentManager
                .beginTransaction();
        /*if (null != activeFragment) {
            fragmentTransaction.hide(activeFragment);
        }*/

        fragmentTransaction.replace(R.id.container, fragmentToAdd,
                fragmentTag);

        if (supportFragmentManager.getBackStackEntryCount() > 1) {
            supportFragmentManager.popBackStack();
        }
        fragmentTransaction.addToBackStack(fragmentTag);
        fragmentTransaction.commit();
        supportFragmentManager.executePendingTransactions();
        //Log.i(TAG, "BackStackEntryCount: " + supportFragmentManager.getBackStackEntryCount());
    }
 
Example 8
Source File: MqttSettingsCodeReaderFragment.java    From Bluefruit_LE_Connect_Android_V2 with MIT License 6 votes vote down vote up
@Override
public void onCodeScanned(String contents) {
    Log.d(TAG, "Code Scanned: " + contents);
    if (isCodeAlreadyScanned) {
        return;
    }       // To avoid double scans and pop 2 times the fragment
    isCodeAlreadyScanned = true;

    // Beep
    final ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100);
    tg.startTone(ToneGenerator.TONE_PROP_BEEP);

    //
    mListener.onPasswordUpdated(contents);

    // Pop current fragment
    FragmentActivity activity = getActivity();
    if (activity != null) {
        FragmentManager fragmentManager = activity.getSupportFragmentManager();
        fragmentManager.popBackStack();
    }
}
 
Example 9
Source File: BaseActivity.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
public void backToMain() {
    FragmentManager fm = getBaseActivity().getSupportFragmentManager();
    int c = fm.getBackStackEntryCount();
    for (int i = 0; i < c; i++) {
        fm.popBackStack();
    }
}
 
Example 10
Source File: FleetConnectivityActivity.java    From here-android-sdk-examples with Apache License 2.0 5 votes vote down vote up
/**
 * Pushes the @{link JobDetailsFragment} on the stack.
 *
 * @param jobId ID of the job of which the details should be displayed.
 */
@Override
public void showJobDetails(String jobId) {
    FragmentManager fm = getSupportFragmentManager();
    if (fm.getBackStackEntryCount() > 0 && JobDetailsFragment.TAG.equals(fm.getBackStackEntryAt(fm.getBackStackEntryCount() - 1).getName())) {
        fm.popBackStack();
    }
    FragmentTransaction ft = fm.beginTransaction();
    ft.setCustomAnimations(R.anim.right_enter, R.anim.right_exit, R.anim.right_enter, R.anim.right_exit);
    ft.add(R.id.container, JobDetailsFragment.newInstance(jobId), JobDetailsFragment.TAG);
    ft.addToBackStack(JobDetailsFragment.TAG);
    ft.commit();
}
 
Example 11
Source File: ApplicationPreferencesActivity.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onSupportNavigateUp() {
  FragmentManager fragmentManager = getSupportFragmentManager();
  if (fragmentManager.getBackStackEntryCount() > 0) {
    fragmentManager.popBackStack();
  } else {
    // TODO [greyson] Navigation
    Intent intent = new Intent(this, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);
    finish();
  }
  return true;
}
 
Example 12
Source File: AccessLogActivity.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * 前の Fragment に戻ります.
 * <p>
 * 前の Fragment がない場合には Activity を終了します。
 * </p>
 */
void popFragment() {
    FragmentManager manager = getFragmentManager();
    if (manager.getBackStackEntryCount() > 0) {
        manager.popBackStack();
    } else {
        getActivity().finish();
    }
}
 
Example 13
Source File: MqttSettingsCodeReaderFragment.java    From Bluefruit_LE_Connect_Android_V2 with MIT License 5 votes vote down vote up
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);

    if (requestCode != RC_HANDLE_CAMERA_PERM) {
        Log.d(TAG, "Got unexpected permission result: " + requestCode);
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        return;
    }

    if (grantResults.length != 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
        Log.d(TAG, "Camera permission granted - initialize the camera source");
        // we have permission, so create the camerasource
        createCameraSource(kAutoFocus, kUseFlash);
        return;
    }

    Log.e(TAG, "Permission not granted: results len = " + grantResults.length +
            " Result code = " + (grantResults.length > 0 ? grantResults[0] : "(empty)"));

    DialogInterface.OnClickListener listener = (dialog, id) -> {
        FragmentActivity activity = getActivity();
        if (activity != null) {
            FragmentManager fragmentManager = activity.getSupportFragmentManager();
            fragmentManager.popBackStack();
        }
    };

    AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
    builder.setMessage(R.string.mqttcodereader_nocamerapermission)
            .setPositiveButton(android.R.string.ok, listener)
            .show();
}
 
Example 14
Source File: MobiComKitPeopleActivity.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void addFragment(FragmentActivity fragmentActivity, Fragment fragmentToAdd, String fragmentTag) {
    FragmentManager supportFragmentManager = fragmentActivity.getSupportFragmentManager();

    FragmentTransaction fragmentTransaction = supportFragmentManager
            .beginTransaction();
    fragmentTransaction.replace(R.id.layout_child_activity, fragmentToAdd,
            fragmentTag);

    if (supportFragmentManager.getBackStackEntryCount() > 1) {
        supportFragmentManager.popBackStack();
    }
    fragmentTransaction.addToBackStack(fragmentTag);
    fragmentTransaction.commitAllowingStateLoss();
    supportFragmentManager.executePendingTransactions();
}
 
Example 15
Source File: AccessLogActivity.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case android.R.id.home:
            callFragment();
            FragmentManager manager = getSupportFragmentManager();
            if (manager.getBackStackEntryCount() > 0) {
                manager.popBackStack();
            } else {
                finish();
            }
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 16
Source File: BaseActivity.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
public boolean back() {
    FragmentManager fm = getBaseActivity().getSupportFragmentManager();
    if (fm.getBackStackEntryCount() > 0) {
        fm.popBackStack();

        return true;
    }
    return false;
}
 
Example 17
Source File: MainActivity.java    From Bluefruit_LE_Connect_Android_V2 with MIT License 5 votes vote down vote up
private void popFragmentsIfNoPeripheralsConnected() {
    final int numConnectedPeripherals = BleManager.getInstance().getConnectedDevices().size();
    final boolean isLastConnectedPeripheral = numConnectedPeripherals == 0;

    if (isLastConnectedPeripheral && (!kAvoidPoppingFragmentsWhileOnDfu || !isIsDfuInProgress())) {
        Log.d(TAG, "No peripherals connected. Pop all fragments");
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
        fragmentManager.executePendingTransactions();
    }
}
 
Example 18
Source File: BaseActivity.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
public void backToMain() {
    FragmentManager fm = getBaseActivity().getSupportFragmentManager();
    int c = fm.getBackStackEntryCount();
    for (int i = 0; i < c; i++) {
        fm.popBackStack();
    }
}
 
Example 19
Source File: BaseActivity.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
public boolean back() {
    FragmentManager fm = getBaseActivity().getSupportFragmentManager();
    if (fm.getBackStackEntryCount() > 0) {
        fm.popBackStack();

        return true;
    }
    return false;
}
 
Example 20
Source File: DashboardActivity.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
private void popOverlay(Fragment frag) {
    if(frag != null) {
        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction trans = manager.beginTransaction();
        trans.remove(frag);
        trans.commit();
        manager.popBackStack();
    }
}