Android: Don't save fragment state

We have custom constructors and state which break this.
This commit is contained in:
Connor McLaughlin 2021-03-06 16:16:25 +10:00
parent fd7d77bc70
commit cc48b6cc7b
3 changed files with 20 additions and 19 deletions

View File

@ -16,6 +16,8 @@ import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentFactory;
import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
@ -48,6 +50,12 @@ public class ControllerMappingActivity extends AppCompatActivity {
} }
} }
@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.remove("android:support:fragments");
}
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present. // Inflate the menu; this adds items to the action bar if it is present.

View File

@ -50,10 +50,6 @@ public class MainActivity extends AppCompatActivity {
private boolean mHasExternalStoragePermissions = false; private boolean mHasExternalStoragePermissions = false;
private boolean mIsShowingGameGrid = false; private boolean mIsShowingGameGrid = false;
public MainActivity() {
getSupportFragmentManager().setFragmentFactory(createFragmentFactory());
}
private static String getTitleString() { private static String getTitleString() {
String scmVersion = AndroidHostInterface.getScmVersion(); String scmVersion = AndroidHostInterface.getScmVersion();
final int gitHashPos = scmVersion.indexOf("-g"); final int gitHashPos = scmVersion.indexOf("-g");
@ -113,21 +109,6 @@ public class MainActivity extends AppCompatActivity {
mIsShowingGameGrid = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("Main/GameGridView", false); mIsShowingGameGrid = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("Main/GameGridView", false);
} }
private FragmentFactory createFragmentFactory() {
return new FragmentFactory() {
@NonNull
@Override
public Fragment instantiate(@NonNull ClassLoader classLoader, @NonNull String className) {
if (className == GameListFragment.class.getName())
return new GameListFragment(MainActivity.this);
else if (className == GameGridFragment.class.getName())
return new GameGridFragment(MainActivity.this);
return super.instantiate(classLoader, className);
}
};
}
private void switchGameListView() { private void switchGameListView() {
mIsShowingGameGrid = !mIsShowingGameGrid; mIsShowingGameGrid = !mIsShowingGameGrid;
PreferenceManager.getDefaultSharedPreferences(this) PreferenceManager.getDefaultSharedPreferences(this)
@ -181,6 +162,12 @@ public class MainActivity extends AppCompatActivity {
completeStartup(); completeStartup();
} }
@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.remove("android:support:fragments");
}
private void completeStartup() { private void completeStartup() {
if (!AndroidHostInterface.hasInstance() && !AndroidHostInterface.createInstance(this)) { if (!AndroidHostInterface.hasInstance() && !AndroidHostInterface.createInstance(this)) {
Log.i("MainActivity", "Failed to create host interface"); Log.i("MainActivity", "Failed to create host interface");

View File

@ -34,6 +34,12 @@ public class SettingsActivity extends AppCompatActivity {
} }
} }
@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.remove("android:support:fragments");
}
@Override @Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) { public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == android.R.id.home) { if (item.getItemId() == android.R.id.home) {