Android Question Allowing KEYCODE_BACK causes error on restart

DaveW

Active Member
Licensed User
Longtime User
I was allowing the Keycode_Back to pass through at Activity_KeyPress level. However if I do that with a Released version, when the app is restarted from the smartphone icon I get this error:

An error has occured in sub:main_mainpanelslayout (java line 4126)
java.lang.RuntimeException: Object should first be initialized (Panel).
Continue?

If I say No and re-terminate the app, it will start correctly the next attempt.
If I say Yes I just get a blank screen.

All my layouts are designed completely in the Visual Designer, I am not making the layouts from scratch in code. I have also been through the entire app adding [panelname].initialize("") for every panel that is mentioned in code. When I did go through the code, the error line changed from 4113 to 4126 so I seem to have done something to move the error down a bit. But I don't have any more panels that can be initialized.

Obviously there is something that needs to be initialized - or is not shut down correctly when the Keycode_Back keypress is allowed to pass through. The problem is what? Does anyone have any ideas where I should look?

David.
 

DaveW

Active Member
Licensed User
Longtime User
Hi Erel,

Yes, the layout was being loaded in FirstTime. However moving it out of FirstTime did not help, the same error remained. I also tried moving all the [panel].Initialize statements out of FirstTime as well, still the same error.

And anyway, why should that matter? I thought the Keycode_Back at the activity level was exiting the app so when restarting it, FirstTime would again be true?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

DaveW

Active Member
Licensed User
Longtime User
Thanks for taking the time to try to explain this too me. I have seen this before but as a Windows programmer, I have a really tough time trying to understand the odd (to me) way that Android apps live and die!

For now (and maybe always) I will just consume the Back button press and prevent the user exiting the app.

David.
 
Upvote 0

MaFu

Well-Known Member
Licensed User
Longtime User
For now (and maybe always) I will just consume the Back button press and prevent the user exiting the app.
This is the wrong way.
You should post the code so we can check what goes wrong.
 
Upvote 0

DaveW

Active Member
Licensed User
Longtime User
Hi Manfred,

I appreciate your comment, however all I am doing now is Return False instead of Return True.

As the error occurs 'outside' the debuggable code, I would have to post the full (commercial) application with about 6000 lines of code plus 12 layouts. I don't think this would be appropriate to post!
 
Upvote 0
Top