From 5c31c21d06cfbf9c2fca0a32ca0d7c185566b625 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Wed, 2 Dec 2020 14:50:16 +0800 Subject: [PATCH] Try fixing IllegalStateException for fragments in various Activities. --- .../infinityforreddit/activities/AccountPostsActivity.java | 6 ++++-- .../infinityforreddit/activities/FilteredThingActivity.java | 5 ++--- .../activities/SearchSubredditsResultActivity.java | 1 + .../activities/SubredditSelectionActivity.java | 5 ++--- .../activities/ViewMultiRedditDetailActivity.java | 6 +++--- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountPostsActivity.java index 74cf5393..27292222 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountPostsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/AccountPostsActivity.java @@ -143,10 +143,12 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE); mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE); isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE); - mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE); - getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_account_posts_activity, mFragment).commit(); + if (!mNullAccessToken && mAccessToken == null) { getCurrentAccountAndInitializeFragment(); + } else { + mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE); + getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_account_posts_activity, mFragment).commit(); } } else { getCurrentAccountAndInitializeFragment(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredThingActivity.java index 42a366e9..d2bfc20f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredThingActivity.java @@ -159,12 +159,11 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE); mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE); - mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE); - getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_filtered_posts_activity, mFragment).commit(); - if (!mNullAccessToken && mAccessToken == null) { getCurrentAccountAndBindView(filter); } else { + mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE); + getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_filtered_posts_activity, mFragment).commit(); bindView(filter, false); } } else { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchSubredditsResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchSubredditsResultActivity.java index 21ebd255..9014ce1a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchSubredditsResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchSubredditsResultActivity.java @@ -114,6 +114,7 @@ public class SearchSubredditsResultActivity extends BaseActivity implements Acti mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE); mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE); mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE); + if (!mNullAccessToken && mAccessToken == null) { getCurrentAccountAndInitializeFragment(query); } else { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditSelectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditSelectionActivity.java index 8742ad7c..eb63d756 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditSelectionActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditSelectionActivity.java @@ -133,12 +133,11 @@ public class SubredditSelectionActivity extends BaseActivity implements Activity mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE); mAccountProfileImageUrl = savedInstanceState.getString(ACCOUNT_PROFILE_IMAGE_URL); - mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE); - getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_subreddit_selection_activity, mFragment).commit(); - if (!mNullAccessToken && mAccountName == null) { getCurrentAccountAndBindView(); } else { + mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE); + getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_subreddit_selection_activity, mFragment).commit(); bindView(false); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java index 72ff2341..2caec58b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewMultiRedditDetailActivity.java @@ -158,11 +158,11 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE); isInLazyMode = savedInstanceState.getBoolean(IS_IN_LAZY_MODE_STATE); - mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE_KEY); - getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_multi_reddit_detail_activity, mFragment).commit(); - if (!mNullAccessToken && mAccessToken == null) { getCurrentAccountAndInitializeFragment(); + } else { + mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE_KEY); + getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_multi_reddit_detail_activity, mFragment).commit(); } } else { getCurrentAccountAndInitializeFragment();