Skip to content

Commit

Permalink
Merge pull request #71 from pserwylo/fix-crash-pinned-mode
Browse files Browse the repository at this point in the history
Attempt to fix common crash with pinned mode when not in foreground.
  • Loading branch information
nicolasbrailo authored Sep 26, 2023
2 parents 4519d75 + 5405d36 commit 02124d5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 25 deletions.
23 changes: 1 addition & 22 deletions app/src/main/java/com/nicobrailo/pianoli/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@ protected void onResume() {
lock_app();
}

public void quitApp() {
unlock_app();
this.startActivity(new Intent(this, MainActivity.class));
moveTaskToBack(true);
}

private static final int REQUEST_CONFIG = 1;

@Override
Expand All @@ -87,22 +81,7 @@ public void onConfigOpenRequested() {
// child accidentally getting to the settings screen.
unlock_app();

startActivityForResult(new Intent(this, SettingsActivity.class), REQUEST_CONFIG);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);


if (requestCode == REQUEST_CONFIG) {
if (resultCode == SettingsActivity.RESULT_QUIT) {
quitApp();
}

// Don't need to lock the app if the user just hit the "Up" button in the action bar here again,
// because onResume would have already been called.
}
startActivity(new Intent(this, SettingsActivity.class));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
public class SettingsActivity extends AppCompatActivity {

public static final String SOUNDSET_DIR_PREFIX = "soundset_";
public static final int RESULT_QUIT = 1;

public SettingsActivity() {
// empty ctor may be required for fragments
Expand All @@ -37,8 +36,11 @@ protected void onCreate(Bundle savedInstanceState) {
}

private void onQuit() {
setResult(RESULT_QUIT);
finish();
// Really don't want to go back to the main activity after quiting, so a normal
// finish() is no good (https://stackoverflow.com/questions/17719634/how-to-exit-an-android-app-programmatically).
// If we return to the main activity, it will prompt to lock the screen again, as if
// it was just launched.
finishAffinity();
}

@Override
Expand Down

0 comments on commit 02124d5

Please sign in to comment.