Fix some crashes reported through google play (#8579)

### Description

Possible fixes for some crashes reported through google play

### Checklist
<!-- 
To help us keep the issue tracker clean and work as efficient as
possible,
  please make sure that you have done all of the following.
You can tick the boxes below by placing an x inside the brackets like
this: [x]
-->
- [x] I have read the contribution guidelines:
https://github.com/AntennaPod/AntennaPod/blob/develop/CONTRIBUTING.md#submit-a-pull-request
- [x] I have performed a self-review of my code, going through my
changes line by line and carefully considering why this line change is
necessary
- [x] I have run the automated code checks using `./gradlew checkstyle
lint`
- [x] My code follows the style guidelines of the AntennaPod project:
https://antennapod.org/contribute/develop/app/code-style
- [x] I have mentioned the corresponding issue and the relevant keyword
(e.g., "Closes: #xy") in the description (see
https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue)
- [x] If it is a core feature, I have added automated tests
This commit is contained in:
Hans-Peter Lehmann
2026-07-09 08:48:05 +02:00
committed by GitHub
parent df29c2fe27
commit 3d1c1a79ba
3 changed files with 12 additions and 7 deletions

View File

@ -492,20 +492,17 @@ public class MainActivity extends CastEnabledActivity implements NavigationToolb
public void loadFragment(Fragment fragment) {
FragmentManager fragmentManager = getSupportFragmentManager();
// clear back stack
for (int i = 0; i < fragmentManager.getBackStackEntryCount(); i++) {
fragmentManager.popBackStack();
}
// Clear all synchronously to avoid conflicting with predictive back gesture cancellation
fragmentManager.popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
FragmentTransaction t = fragmentManager.beginTransaction();
t.replace(R.id.main_content_view, fragment, MAIN_FRAGMENT_TAG);
fragmentManager.popBackStack();
// TODO: we have to allow state loss here
// since this function can get called from an AsyncTask which
// could be finishing after our app has already committed state
// and is about to get shutdown. What we *should* do is
// not commit anything in an AsyncTask, but that's a bigger
// change than we want now.
t.commitAllowingStateLoss();
t.commitNowAllowingStateLoss();
if (drawerLayout != null) { // Tablet layout does not have a drawer
drawerLayout.closeDrawer(navDrawer);

View File

@ -93,6 +93,9 @@ public class HomeFragment extends Fragment implements Toolbar.OnMenuItemClickLis
}
private void addSection(Fragment section) {
if (section == null) { // Can happen when stored settings reference a section that no longer exists
return;
}
FragmentContainerView containerView = new FragmentContainerView(getContext());
containerView.setId(View.generateViewId());
viewBinding.homeContainer.addView(containerView);