Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onBackPressed() method doesn't get called or doesn't exist #459

Closed
hunterkiddo opened this issue May 10, 2018 · 1 comment
Closed

onBackPressed() method doesn't get called or doesn't exist #459

hunterkiddo opened this issue May 10, 2018 · 1 comment

Comments

@hunterkiddo
Copy link

hunterkiddo commented May 10, 2018

I'm currently trying to intercept the back key using processing android mode, since I only have one activity, as I'm handling everything through UI. Processing will call keyPressed() and keyReleased() when the back key is pressed, but then after the code runs will exit my app, which completely ruins the usability. When I try to override onBackPressed() it tells me there doesn't exist a super method named onBackPressed(), so I can't override it. My attempted code in keyReleased() all gets called, but doesn't change the fact that the activity is closed.

Code:
@Override
public void keyReleased() {
if (key == CODED) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
println("back key released, keyCode: " + keyCode);
keyCode = 1; // don't quit
key = 1; //I said don't quit
}
}
}

//@Override //doesn't work
void onBackPressed() {
//supposed to do nothing
println("back pressed"); //never printed
}

PLEASE HELP!!!!

UPDATE:
on further inspection this is the same issue as #414 , but I don't understand how to implement the solution described by codeanticode: "It could still be added in the main activity that contains the Processing sketch, but it is not immediately obvious what the best implementation could be"
public class MainActivity extends AppCompatActivity {
...
@Override
public void onBackPressed() {
if (sketch != null) {
// check if sketch has a method call back(), etc.
return;
}
super.onBackPressed();
}
}

How do I get to this file to edit the onBackPressed() code?

If I can't get to it, doesn't it make way more sense for Processing to get rid of super.onBackPressed(); in the MainActivity so that people can handle it themselves in keypressed() and keyreleased() instead of always just closing out of the app? Or at least defining a mode that enables it or not. I mean at that point it literally breaks the app no matter what.

@codeanticode
Copy link
Member

@hunterkiddo the method suggested in #414 requires modifying the activity template that Processing uses to turn the sketch into an Android app... I will mark this as a duplicate and let's continue the discussion in the original issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants