SFML community forums

General => SFML wiki => Topic started by: Demir on February 06, 2016, 03:08:46 pm

Title: Android example can not close on Escape
Post by: Demir on February 06, 2016, 03:08:46 pm
Hello,

I try to run android example through wiki "Tutorial: Building SFML for Android".
As was expected it worked.

I added Escape key release checking to close via Back button on the tablet.
if (event.type == sf::Event::KeyReleased)
{
  if (event.key.code == sf::Keyboard::Escape)
  window.close();
}
 
It can not close properly.
Any idea ? What can I do ?

Thanks

Edit:
I noticed same question at this link :(
http://en.sfml-dev.org/forums/index.php?PHPSESSID=ot7h2v1oj9hmn1qop9q78i4s03&topic=19145.msg141108#msg141108
Title: Re: Android example can not close on Escape
Post by: Jesper Juhl on February 06, 2016, 03:18:41 pm
Have you tried logging what key.code is actually generated? Maybe it's just not Escape as you expect but some other key code...
Title: Re: Android example can not close on Escape
Post by: Demir on February 06, 2016, 03:49:34 pm
Returning key code is 36 it is Escape in "Keyboard::Key" enum.

On Escape It closes the example applicatin but after that .... the example app can not work again only black screen appears.
Title: Re: Android example can not close on Escape
Post by: Mario on February 10, 2016, 12:42:38 pm
Make sure to leave your main() after you've closed the window. Any chance you forgot doing that?
Title: Re: Android example can not close on Escape
Post by: Demir on February 11, 2016, 11:45:09 am
Quote
Make sure to leave your main() after you've closed the window. Any chance you forgot doing that?

I hope it gives you an idea to find close problem.
as I can see
std::exit(0);
can close completely.

1. I tried to control via isClosed boolean var. does not work
                if (event.key.code == sf::Keyboard::Escape)
                {
                    isClose = true;
                    window.close();
                }
 

2. I tried to return 0 does not work
window.close();
return 0;
 

Title: Re: Android example can not close on Escape
Post by: R23MJ on May 03, 2016, 03:44:21 pm
From what I remember when working with iOS, you cannot actually close the application from within the application. Which makes sense if you think about it, the user needs to close the application via system supplied ways, i.e. pressing home button.
Title: Re: Android example can not close on Escape
Post by: korczurekk on May 04, 2016, 05:19:28 pm
From what I remember when working with iOS, you cannot actually close the application from within the application. Which makes sense if you think about it, the user needs to close the application via system supplied ways, i.e. pressing home button.
You can close app within code on iOS, but if so you have no chances for getting into appstore. And android applications often close themselves, so there must be some other error.
Title: Re: Android example can not close on Escape
Post by: ChronicRat on May 04, 2016, 06:11:04 pm
The only way to totally finish Android app is to call exit() or std::terminate() function. exit() is bad if you'll relaunch app immediately after exit. terminate() is bad because it shows popup window with error message (but it's rarely, tbh I saw it two or three times).