In my app, I'm doing a network operation in a thread. In the result of the network operation, I show a toast and replace the fragment using the runOnUiThread() method. But the app gets hanged after the fragment is replaced.
Here is my code
getBaseActivity().runOnUiThread(() -> {
hideProgressDialog();
showToastAlertDialog(getString(R.string.mystring));
MyFragment fragment = new MyFragment();
getBaseActivity().replaceFragment(getActivity(), fragment, false, R.id.baseFragment);
BaseActivity.java
public void replaceFragment(FragmentActivity activity, Fragment fragment, boolean addToBackStack, int baseFragment) {
try {
FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
ft.replace(baseFragment, fragment);
if (addToBackStack) {
ft.addToBackStack(null);
}
ft.commit();
} catch (Exception exception) {
CXLog.e(TAG, "Exception: " + exception.getLocalizedMessage(), exception);
}
}