Android: Fix SettingsActivity back stack behavior after stop+start

Fixes the behavior where the settings activity would go back to
the top-level menu after switching to a different app and back.
This commit is contained in:
JosJuice 2020-08-21 17:09:30 +02:00
parent bed6a4f12f
commit 1ba43c726d
3 changed files with 4 additions and 33 deletions

View File

@ -96,14 +96,12 @@ public final class SettingsActivity extends AppCompatActivity implements Setting
getWindowManager().getDefaultDisplay().getRotation()); getWindowManager().getDefaultDisplay().getRotation());
} }
@Override
public void onBackPressed() {
mPresenter.onBackPressed();
}
@Override @Override
public void showSettingsFragment(String menuTag, boolean addToStack, String gameID) { public void showSettingsFragment(String menuTag, boolean addToStack, String gameID) {
if (!addToStack && getFragment() != null) {
return;
}
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
if (addToStack) { if (addToStack) {
@ -116,7 +114,6 @@ public final class SettingsActivity extends AppCompatActivity implements Setting
} }
transaction.addToBackStack(null); transaction.addToBackStack(null);
mPresenter.addToStack();
} }
transaction.replace(R.id.frame_content, SettingsFragment.newInstance(menuTag, gameID), FRAGMENT_TAG); transaction.replace(R.id.frame_content, SettingsFragment.newInstance(menuTag, gameID), FRAGMENT_TAG);
@ -207,11 +204,6 @@ public final class SettingsActivity extends AppCompatActivity implements Setting
Toast.makeText(this, message, is_long ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT).show(); Toast.makeText(this, message, is_long ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT).show();
} }
@Override
public void popBackStack() {
getSupportFragmentManager().popBackStackImmediate();
}
@Override @Override
public void onSettingChanged() { public void onSettingChanged() {
mPresenter.onSettingChanged(); mPresenter.onSettingChanged();

View File

@ -22,8 +22,6 @@ public final class SettingsActivityPresenter {
private Settings mSettings = new Settings(); private Settings mSettings = new Settings();
private int mStackCount;
private boolean mShouldSave; private boolean mShouldSave;
private DirectoryStateReceiver directoryStateReceiver; private DirectoryStateReceiver directoryStateReceiver;
@ -45,7 +43,6 @@ public final class SettingsActivityPresenter {
} }
public void onStart() { public void onStart() {
this.mStackCount = 0;
prepareCitraDirectoriesIfNeeded(); prepareCitraDirectoriesIfNeeded();
} }
@ -117,19 +114,6 @@ public final class SettingsActivityPresenter {
NativeLibrary.ReloadSettings(); NativeLibrary.ReloadSettings();
} }
public void addToStack() {
mStackCount++;
}
public void onBackPressed() {
if (mStackCount > 0) {
mView.popBackStack();
mStackCount--;
} else {
mView.finish();
}
}
public void onSettingChanged() { public void onSettingChanged() {
mShouldSave = true; mShouldSave = true;
} }

View File

@ -55,11 +55,6 @@ public interface SettingsActivityView {
*/ */
void showToastMessage(String message, boolean is_long); void showToastMessage(String message, boolean is_long);
/**
* Show the previous fragment.
*/
void popBackStack();
/** /**
* End the activity. * End the activity.
*/ */