I can't correctly exit from PlayN GameActivity using Back button.
I am using following code:
public class Loader extends GameActivity {
public void main(){
PlayN.run(new Game());
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
finish();
}
return super.onKeyDown(keyCode, event);
}
}
but it is not correct enough.
GameActivity closes, but if you run game again, it will shows two copies of the same game with two working threads (previous and current) and in root layer you will see two copies of root layers.
I'ts really stupid, but how to do finish() correctly to destroy GameActivity with all his internal threads/listeners/layers/audio completely from mem?
this
@Override
public boolean onKeyDown(int keyCode, KeyEvent event){
if (keyCode == KeyEvent.KEYCODE_BACK) {
this.finish();
}
return super.onKeyDown(keyCode, event);
}
works only if you didn't used PlayN.assets().getSound(...).play() in your game, otherwise all Activity crashes on exit.
I found a small workaround for this, you should override onDestroy method in your GameActivity by this:
@Override
public void onDestroy() {
super.onStop();
try {
super.onDestroy();
} catch (IllegalStateException e) {
android.util.Log.e("Easy", "JVM: playn.android.AndroidCompressedSound.MediaPlayer melts my brain!.");
}
}
but still have no idea why this exception happens.