Android Question Bad effect when closing an app

Sabotto

Active Member
Licensed User
When I close my app, with the click on "Exit", this effect is created as if the layout "exits and re-enters" (you see the white for a moment) before disappearing completely. The code I use to terminate launches a routine (StopSophosClient) which uses an Intent to terminate a service (OpenVPN) which I start at the beginning of the program to join a VPN. The StartActivity (Intent) causes this annoying flicker. Any suggestions?

piccolo spezzone app .gif


B4X:
' in B4XMainPage
Private Sub btnExit_Click

    StopSophosClient
    Sleep(2000)
    B4XPages.ClosePage(Me)
    ExitApplication
          
End Sub

Sub StopSophosClient
    Dim i As Intent
    i.Initialize(i.ACTION_MAIN, "")
    i.SetComponent("de.blinkt.openvpn/.api.DisconnectVPN")
    i.PutExtra("de.blinkt.openvpn.shortcutProfileName", "VPN_Telecontrollo")
    StartActivity(i) ' ---> This instruction causes the "undesirable effect"
End Sub
 

Star-Dust

Expert
Licensed User
Longtime User
I think it is the intent that makes the control return to the system and then when you return your app that was paused reappears
 
Upvote 0

Sabotto

Active Member
Licensed User
I noticed this thing (see code)
B4X:
Private Sub btnExit_Click

    btnStart.Enabled=False 'Disabled the button!!!'
    btnExit.Enabled=False
    GL.bVPNstarted=False
    StopSophosClient
    'When the code arrives here btnStart is again Enabled!!!
    'So it is as if the Layout was restarted
    Sleep(2000)
    ToastMessageShow("VPN disconnessa",False)
    B4XPages.ClosePage(Me)
    ExitApplication
           
End Sub
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
'So it is as if the Layout was restarted
It probably was, at least Activity_Resume will be run as the Activity came to the fore, maybe Activity_Create also. You can try putting a flag in Process_Globals and checking it at some appropriate places. Have an experiment.
 
Upvote 0

Sabotto

Active Member
Licensed User
It probably was, at least Activity_Resume will be run as the Activity came to the fore, maybe Activity_Create also. You can try putting a flag in Process_Globals and checking it at some appropriate places. Have an experiment.
Yes, the B4xPage_Appear event is triggered. And that's why I found btnStart.enabled = True.
But beyond that, there is nothing special inside Appear. I can't understand why he does that "go out / in" layout. It should remain fixed !
B4X:
Sub B4xPage_Appear
    btnStart.Enabled=True
    'and nothing more '
End Sub
Do not use ExitApplication.
Yes, I deleted it. But that's not the problem
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Secondo me, invece, il principale problema (non è detto che sia il solo) è che quella routine utilizzi un Intent per avviare nuovamente l'Activity Main (StartActivity(i))
Translation:
In my opinion, however, the main problem (it is not necessarily the only one) is that routine uses an Intent to start the Activity Main again (StartActivity (i))
 
Upvote 0

Sabotto

Active Member
Licensed User
There is no doubt that the effect is caused by the StartActivity (i) statement. But I'm looking for the solution and not the cause.
Even when I launch the VPN service I use a StartActivity (intent), but in that case the effect does not happen.
B4X:
Sub StartSophosClient
    Dim i As Intent
    i.Initialize(i.ACTION_MAIN, "")
    i.SetComponent("de.blinkt.openvpn/.LaunchVPN")
    i.PutExtra("de.blinkt.openvpn.shortcutProfileName", "VPN_Telecontrollo")
    i.PutExtra("de.blinkt.openvpn.AUTOCONNECT", True)
    StartActivity(i)
End Sub

Sub StopSophosClient
    Dim i As Intent
    i.Initialize(i.ACTION_MAIN, "")
    i.SetComponent("de.blinkt.openvpn/.api.DisconnectVPN")
    i.PutExtra("de.blinkt.openvpn.shortcutProfileName", "VPN_Telecontrollo")
    StartActivity(i)
End Sub
 
Upvote 0

Sabotto

Active Member
Licensed User
The two routines are to start (StartSophosClient) and close (StopSophosClient) an external app called "OpenVPN" to enter in a VPN, where I need to ping. The first is called as soon as my app starts and the second when I close my app.

Maybe I could use the same Intent? Or maybe there is another method to start and stop OpenVPN?
 
Last edited:
Upvote 0

Sabotto

Active Member
Licensed User
Sorry...
Maybe you haven't read from the beginning ...?
I call B4xPages.ClosePage when I exit my app (see btnExit_click)
ExitApplication I eliminated it, ignore it.
Before exiting my app, I also close the VPN service that I had launched when starting my app
 
Last edited:
Upvote 0
Top