How can I freeze application for 10 seconds?

peve9

Member
Licensed User
Longtime User
Hi everyone,
I have a problem with my apllication...
I have a simple button and on button click the application has to query a DB.

B4X:
Sub Button1_Click
   'query a DB
'this takes about 10 seconds
End Sub

I need to make the application freeze during this period so the user can't do anything... How can I do this? Is there some libraries or particular istruction? :BangHead:

Thanks to all!
 

stevel05

Expert
Licensed User
Longtime User
Add an invisible panel over the whole screen and consume it's click and long_click events (with empty Click and Long_Click Subs). Remove it when you want to continue.
 
Upvote 0

peve9

Member
Licensed User
Longtime User
Add an invisible panel over the whole screen and consume it's click and long_click events (with empty Click and Long_Click Subs). Remove it when you want to continue.

I have tryed but it doesn't work..
Even if i put
B4X:
Panel1.visible=true
as first istruction, the panel appears only at the end of the routines and in this way I can click too many times on the button and this is what i want to avoid.

Any other suggestions? :sign0085::sign0085:
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You may need to add a DoEvents after adding the panel to get it drawn immediately, but if that doesn't work, if you post your code so we can see exactly what the problem is, we can help.
 
Upvote 0

grant1842

Active Member
Licensed User
Longtime User
What method/library are you using to query? If it's synchronous then you don't need to freeze anything as the application won't move further until the query is completed.
 
Upvote 0

peve9

Member
Licensed User
Longtime User
What method/library are you using to query? If it's synchronous then you don't need to freeze anything as the application won't move further until the query is completed.

Well, this is the code that I'm using
B4X:
If File.Exists(File.DirInternal,"ShutApp.db") Then
         SQL1.Initialize(File.DirInternal, "ShutApp.db", False)
      Else
         'creo il database
         SQL1.Initialize(File.DirInternal, "ShutApp.db", True)
         'creo la tabella contatti
         SQL1.ExecNonQuery("CREATE TABLE Contatti (nome TEXT , numero TEXT, immagine BLOB, io INTEGER)")   'id=1 sono io e i miei dati
         SQL1.ExecNonQuery("CREATE TABLE Messaggi (interlocutore TEXT , testo TEXT, inviato INTEGER)") '2ricevuto 1 inviato
      End If
      

      Dim conta As Int
      Dim Rubrica As Contacts   'ci permette di accedere alla rubrica
      Dim listaContatti As List   'lista dei contatti della rubrica
      listaContatti = Rubrica.GetAll   
      For i = 0 To listaContatti.Size - 1
         Dim Contatto As Contact   'singolo contatto
         Dim nome,numero As String
         Dim photo As Bitmap
         
         Contatto= listaContatti.Get(i) 'ottengo il contatto
         nome = Contatto.Name 'ottengo i dati del contatto
         numero = Contatto.PhoneNumber
         photo = Contatto.GetPhoto
         
         If SQL1.ExecQuerySingleResult("SELECT count(*) FROM Contatti WHERE numero = '" & numero & "'") = 0 Then
            'allora il contatto non è presente nell lista e va aggiunto
            If photo = Null Then
               photo =LoadBitmap(File.DirAssets,"android.bmp")
            End If
            
            'trasforma la fotografia e inserisce tutto nel database (mi sa che non va un cazzo)
            Dim OutST As OutputStream
            Dim Buffer() As Byte
            
            OutST.InitializeToBytesArray(1000)
            photo.WriteToStream(OutST,1,"PNG")
            Buffer = OutST.ToBytesArray
            conta=conta+1
            SQL1.ExecNonQuery2("INSERT INTO Contatti VALUES(?, ?, ?, ?)", Array As Object(nome,numero,Buffer,0))   
         End If
         
      Next

I'm using SQL library :sign0085:
Thanks :sign0089:
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
For completeness, as your code doesn't show it you should have something like:
In Sub Globals you should have:

B4X:
Dim StopTouchPnl As Panel

In Activity_Create you should have:

B4X:
StopTouchPnl.Initialize("StopTouch")
Activity.AddView(StopTouchPnl,0,0,100%x,100%Y)
StopTouchPnl.Visible=False

Where you want the panel to display you should have:

B4X:
StopTouchPnl.Visible=True
DoEvents

Where you want the panel removed you should have:

B4X:
StopTouchPnl.Visible=False

And you should have two empty subs:

B4X:
Sub StopTouch_Click
   'LeaveBlank
End Sub

Sub StopTouch_LongClick
   'LeaveBlank
End Sub
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
I would disable the buttons or anything clickable before going to the dabase,
and then enable them back when I am done.

Sub Pseudocode
---disable AllClickableViews
-------GoLookForSomethingInDB
-------If FoundSomethingUsful THEN
-----------ProcessIt
-------End If
---Enable AllClickableViews

End sub
 
Last edited:
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
why not use a progress dialog and close it once the data has loaded.
 
Upvote 0
Top