Shutdown and startup of app

enonod

Well-Known Member
Licensed User
Longtime User
I am closing my app with Activity.Finish after trapping the Back button and asking a question.
Under debug (sent fresh each test) it is perfect.
When sent as Release and started from a Shortcut it sometimes starts at a point with the question on the screen, even though that panel was removed mbefore Activity.Finish.
If the device is turned off then on and try again it is perfect.
Assuming that it is being retained is there a way to kill it so that it always starts at the start?
It is entirely self contained. I have read various threads and am unsure.
Thank you
 

enonod

Well-Known Member
Licensed User
Longtime User
Thank you Erel. The rest 'seems' irrelevant and is a bit convoluted to post but essentially the comments explain.
[Edit]Is the problem likely to be caused by the stack not having returned from all subs? If it has anything to do with that, is there a way to clear the stack first?
B4X:
'Save name and score on Back button, close after choice, if player named
Sub Activity_KeyPress (KeyCode As Int) As Boolean 
   'If the first action is Back key then allow close immediately, otherwise ask.
   If bStarted=False Then Return False
   If KeyCode = KeyCodes.KEYCODE_BACK AND bShutTrap=False Then
      bShutTrap=True
      pCommon.RemoveView
   'Disable Help and Undo, other buttons are disbled by form being called, Common(fc)
      bl.Enabled=False
      Common(fc)
      Return True
   Else
      'temporary disable keycodes except Back and multi Back? TEST!!;
      Return True
   End If
End Sub

...'Key_Click code when the answer is YES save game
      Case "KbdFinish"
            etName=pBack.tag
            pKbd=pnl.tag
            If etName.Text<>"" AND etName.text<>"Enter Name" Then
               Player.Name=etName.text
               pKbd.RemoveView
            End If
'this removes the 'question' panel, puts up information panel 'saving...'
            pCommon.RemoveView
            form.Name="Message":form.Title="MESSAGE": form.Msg="Saving Your Game": form.pCol=1: form.tBtn1="": form.tBtn2=""
            Common(form)
            DoEvents
            If Not (File.Exists(File.DirInternal,Player.Name&"#"&Player.Clrs&".dat")) Then
               lGames.Add(Player)
               WriteGames   
            End If
            raf.Initialize(File.DirInternal,Player.Name&"#"&Player.Clrs&".dat",False)
            raf.WriteObject(Player,True,raf.CurrentPosition)
            raf.WriteObject(aGrid,True,raf.CurrentPosition)
            raf.WriteObject(lUndo,True,raf.CurrentPosition)
            raf.WriteInt(Player.Clrs,raf.CurrentPosition)
            raf.Close   
'removes the information panel
            pCommon.RemoveView
            Activity.Finish

   End Select
 
Last edited:
Upvote 0

enonod

Well-Known Member
Licensed User
Longtime User
I have found this thread by agraham...
I also found this suggestion which uses a Global flag, I've edited it from Java to Basic4android
Quote:
Hold a flag in Process_Globals to force close the app, in Activity_Resume check if the force close flag is set. If so call ExitApplication. This will cascade through the entire activity stack and finally get the app completely closed.
Upon trying it, it 'seems' to work. The App does start from the beginning.
However, I notice that when first clicking on the shortcut to start the app after this closedown, the Android screen refreshes (flashes) and I have to click a second time, whence the app starts correctly. I have one self contained Activity, no services either.
My question; is this indicative of what originally is causing the problem?
Thank you for any comments.
 
Upvote 0

enonod

Well-Known Member
Licensed User
Longtime User
Sorry to be dense, can you please expand just a little to give me a clue where to start reading. I have clearly missed something important.
Thank you
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
When sent as Release and started from a Shortcut it sometimes starts at a point with the question on the screen, even though that panel was removed mbefore

There is no simple answer. The activity with all the views is destroyed when you call Activity.Finish. Process_Global variables however are kept. You should check what happens when Activity_Create runs again.
 
Upvote 0

enonod

Well-Known Member
Licensed User
Longtime User
Thank you
 
Upvote 0

enonod

Well-Known Member
Licensed User
Longtime User
Since the problem occurs when starting on the device from a shortcut, how do I invoke a breakpoint when it starts please? The debugger does not respond unless sent each time from the PC.
 
Last edited:
Upvote 0

enonod

Well-Known Member
Licensed User
Longtime User
Thank you again, all over, found the culprit.
 
Upvote 0
Top