0

I want to detect when the backButton is pressed. I saw this method, but it needs to be on the class that implements ApplicationListener and I don't have a class that implements that. Is there another way of doing it?

Community
  • 1
  • 1
  • possible duplicate of [In libgdx, how do I get input from the back button?](http://stackoverflow.com/questions/7223723/in-libgdx-how-do-i-get-input-from-the-back-button) – donfuxx Aug 05 '14 at 12:22
  • Look at the second answer on the question you linked. And actually the first answer doesn't have to be in ApplicationListener...but rather an InputProcessor. They just happened to implement both in the same class in that example. – Tenfour04 Aug 05 '14 at 16:30

3 Answers3

0

You can use onBackPressed() of the current Activity. The default implementation is to finish the current Activity. You can override it as per your requirement. This works with Android 2.0 and above.

@Override
public void onBackPressed() {
    // Override the default implementation
    // ...
}

Source: http://developer.android.com/reference/android/app/Activity.html#onBackPressed()

Code.me
  • 281
  • 3
  • 13
  • Here it does not work because I'm not programming directly on Android, libgdx is a Java game development framework that provides a unified API that works across several platforms like windows, Android, Iphone... – user3365436 Aug 04 '14 at 23:52
0

Use that method and just create a class that is used for detecting button presses?

0
Gdx.input.setCatchBackKey(true)

and then:

if(Gdx.input.isKeyPressed(Keys.BACK)) {
    //Do something
}
Nine Magics
  • 444
  • 4
  • 3