Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Android / Android App occasionally crashes when Back button is pressed

Author
Message
Trek
14
Years of Service
User Offline
Joined: 21st May 2005
Location: NJ, USA
Posted: 11th Oct 2012 14:52
Hi everyone!

I'm working on an app that is supposed to return to the menu if the back button on the phone is presed. For some reason, my app occasionally freezes up when I hit the back button on the phone. Other times, however, it works perfectly and completes the action it should.

Does anyone know what could be making it do this?

Thanks
Ancient Lady
Valued Member
15
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 11th Oct 2012 17:11
How are you catching the back button?

Will you show us the code you use and how it's supposed to go back to your menu?

Cheers,
Ancient Lady
AGK Community Tester
Trek
14
Years of Service
User Offline
Joined: 21st May 2005
Location: NJ, USA
Posted: 11th Oct 2012 17:24
Thanks for the quick reply. Here's the code:



You can see that I delete a lot of sprites, images, etc. before returning to the menu.
Ancient Lady
Valued Member
15
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 11th Oct 2012 17:48
And you are using a Gosub to get to the menu. This means that after the your Menu subroutine hits the return statement it comes back and starts executing the code immediately after the bit you show above.

And if your Menu subroutine doesn't recreate it's sprites, they where probably deleted.

Using Gosub and subroutines instead of functions and function calls can lead to stack issues if you don't use them carefully.

Cheers,
Ancient Lady
AGK Community Tester
Trek
14
Years of Service
User Offline
Joined: 21st May 2005
Location: NJ, USA
Posted: 11th Oct 2012 18:00
do you think I should use a function for my menu instead of a subroutine?
Ancient Lady
Valued Member
15
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 11th Oct 2012 18:27
Personally, I never use a gosub. Every time you use gosub, it puts the return address on the stack. If you don't return from the subroutine, the address stays on the stack. The stack can get corrupted. And your code always needs to be aware that it should be ready for the return.

It can get especially ugly if you do gosub calls from your menu routine and then end up doing a gosub back to the menu from one of those subroutines.

I'd have to see more of your code to know what you should do and I don't want to look at the whole project (I have a lot to do right now).

I would recommend looking at your code and seeing if using functions would be clearer in the flow of it. And, if you use functions, remember that any variables that were used in the subroutines probably would need to be explicitly defined as globals. That would be what you would want to do if you simply turned your subroutines into functions without passing in values.

Cheers,
Ancient Lady
AGK Community Tester
Trek
14
Years of Service
User Offline
Joined: 21st May 2005
Location: NJ, USA
Posted: 11th Oct 2012 18:37
Ok, thanks so much! I'll check through my program and see what might work better...
Ancient Lady
Valued Member
15
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 11th Oct 2012 18:50
Good luck and Happy Programming!

Cheers,
Ancient Lady
AGK Community Tester

Login to post a reply

Server time is: 2019-06-21 00:19:25
Your offset time is: 2019-06-21 00:19:25