Android Question Run a service, wait a time and show this time (effect New Year!)


Active Member
Licensed User
Hi. I'm a beginner in this wonderful world!
In my app, I launch a service (a VPN) and wait about 5 seconds for the service to start. During this time, I show some kind of CountDown (with a label) so that the user understands that he has to wait. There are two questions:
1) Is it right as a method?
2) Is it possible to have an effect on the Label (for example that the numbers seem to approach and then disappear, like when the New Year's countdown is shown on TV? (I don't know if I get the idea) I show the code

Thanks for your suggestions

Private Sub btnStart_Click
    'Start VPN and wait 5 seconds'
    Wait For (StartVPN) complete (Finish As Boolean)
End Sub

Sub StartVPN As ResumableSub
    Dim i As Intent
    i.Initialize(i.ACTION_MAIN, "")
    i.PutExtra("de.blinkt.openvpn.shortcutProfileName", "VPN_Telecontrollo")
    i.PutExtra("de.blinkt.openvpn.AUTOCONNECT", True)
    'Here wait 5 seconds
    timer1.Initialize("timer1", 1000)
    StartTimer(5) ' 5 seconds
    t = Max(0, targetTime - DateTime.Now)
    Do While t > 0
    Return True
End Sub

Sub StartTimer (Seconds As Int)
    targetTime = DateTime.Now + Seconds * DateTime.TicksPerSecond
    timer1.Enabled = True
End Sub

Sub Timer1_Tick
    t = Max(0, targetTime - DateTime.Now)
    Dim  seconds As Int
    seconds = (t Mod DateTime.TicksPerMinute) / DateTime.TicksPerSecond
   lblCountDown.Text=$"$2.0{seconds}"$ ' the label show the countdown
    If t = 0 Then
        timer1.Enabled = False
    End If
End Sub


Active Member
Licensed User
I would look at possibly playing a 5 second video, gif animation, or series of 5 images rather than a label.

On the other hand, good design is NOT to focus the users attention on delays in your App, they want instant response, not spectacularly told to go make a cup of tea every time they open it.
Upvote 0


Active Member
Licensed User
OK. I have resolved with AnimatedCounter and/or B4XLoadingIndicator.
My first question was if the system I adopted is right to pass the time necessary to start the VPN (blocking the user who must not be able to do anything during that time) Instead of waiting for 5 seconds I could check if the service is actually started but I am not yet able to understand how to do it
Upvote 0