Android Question Doevents replaced with Sleep(0) issue

Scantech

Well-Known Member
Licensed User
Longtime User
Hi.

Loading a splash screen with Sleep(0) will not function or display the image at Activity_Create event properly. Adding Doevents 3 times does the trick.

B4X:
Sub Activity_Create(FirstTime As Boolean)
    LoadSplashScreen
    Doevents: Doevents:Doevents   'Will Display the image successfully with image visibility removed in Activity_Resume Event
    'Sleep(0): Sleep(0): Sleep(0)   'Will not display the Image
    'Sleep(1) 'Will display the image successfully but visibility will remain
    'Sleep(x) 'Will not display the Image.  x = any  number other then 1
   
    'My app have codes below that takes few seconds to load
End sub

B4X:
Sub Activity_Resume 
     If imvSplash.IsInitialized  Then imvSplash.Visible  = False
End sub

B4X:
Sub LoadSplashScreen
    imvSplash.Initialize("")
    Activity.AddView(imvSplash, 0, 0, 250dip, 50dip)
    imvSplash.Left             = (Activity.Width - imvSplash.Width)   /2
    imvSplash.Top              = (Activity.Height - imvSplash.Height) /2
    imvSplash.Gravity         = Gravity.FILL
    imvSplash.Bitmap         = LoadBitmap(File.DirAssets, "CarGaugeSplash2.png")
    imvSplash.Visible         = True
End sub
 

BillMeyer

Well-Known Member
Licensed User
Longtime User
And I've just learnt something new again !!
 
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
Can you create a small project with the splash screen and upload it?

I would have implemented it like this:
B4X:
Sub Activity_Create(FirstTime As Boolean)
LoadSplashScreen
Sleep(5000)
HideSplashScreen
...
End Sub

I created a small project and seems to be working ok. No need to upload. However, my project using sleep(5000) works but i prefer the doevents to avoid the 5 seconds delay.
 
Upvote 0

Paulsche

Well-Known Member
Licensed User
Longtime User
In my Splashscreen that works with "sleep(0) instead of Doevents,
but what does not work is myprogressdialog in the zip event.
How would it look like it works without DoEvents?

B4X:
    myProgressDialog.Initialize(Activity, 90%x, -1, 10%y, "","", Colors.DarkGray, 0, "Progress",False)
    Arc.ZipFolder(File.DirDefaultExternal,File.DirRootExternal&"/"&mailbackuppath,datei,"zippen")    'Alle Daten zippen
    myProgressDialog.Hide

Sub zippen_ZipProgression(count As Int,filename As String)
    myProgressDialog.ShowProgress("Daten werden gepackt ..."&count&" %", Colors.White, count)
    DoEvents
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
You should use Async methods. Are you using the Archiver lib or which zipper are you using?
 
Upvote 0

karld

Active Member
Licensed User
Longtime User
I use a splash panel (pnlSplash) like so..

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("main")
   
    pnlSelect.Visible=False
    pnlSplash.Visible=True
    timer1.Initialize("Timer1", 15000)
    timer1.Enabled=True

And check it for a button press here.

B4X:
Sub btnEvent_Click
    Dim send As Button
    send = Sender
   
    Select send.Tag
    Case "BS"
        If lblCode.text.Length >0 Then
            lblCode.text = lblCode.text.substring2(0,lblCode.Text.length - 1)
        End If
    Case "lookup"
        If lblCode.Text.Length >0 Then
        Error_Code = lblCode.Text
        SQLTableRead
        lblResult.Visible = True
        lblCode.Text = ""
        Else
        lblResult.text = "Please enter error code and dispenser type."
        lblResult.Visible = True
        End If
    Case "I AGREE"
        pnlSplash.Visible=False
        timer1.Enabled = False

If they don't click the AGREE button within a certain time then the timer will close it.

B4X:
Sub Timer1_tick
pnlSplash.Visible=False
timer1.Enabled = False
CheckUpdate
End Sub
 
Upvote 0
Top