Android Question How to show progressbar when starting another module?

ronovar

Active Member
Licensed User
Longtime User
How can i update progressbar.progress in Activity_Pause from Module A when module B is loading SQL items and update on screen progressbar.progress with 1% 2% 3%.... until reaches 100% so that Module B is shows and progressbar is hidden.

I try to add progressbar.progress with DoEvents to update progressbar.progress but it is paused and not updating.
 

ronovar

Active Member
Licensed User
Longtime User
Now another question is how can i update progressbar.progress that is defined as global in Module A from Module B when using calling CallSubDelayed...i add to update progressbar.progress in Module B in for loop with ModuleA.progressbar.progress = i but progressbar is always 0 (when i use Log(i) i get always numbers for 1 to 100)
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
if it is a global then just preceed it with the module name, like : Main.MyProgressBar
 
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
Thanks but problem is when i CallSubDelayed it pauses current module and start another module that reads data from SQL...as Module A is Paused it cannot update progressbar because progressbar is Module A witch is paused and when Module B is ready (after 10seconds) it starts Module B and progressbar is at 0% and then hidden.

So i want when i press Item1 in Module A that in Module A is displayed progressbar that is animated and shows percentage of loading items from SQL witch code is in Module B...so when reading is finished in Module B progressbar goes to 100% and then Module B is started.

I try to add reading code of SQL from Module B to Module A and then callsubdelayed in module A works excellent but problem is that i need when reading SQL data to add this data to ListView using AddTwoLinesAndBitmap and i cannot use ListView in Process_Globals so that i can access it from Module A and Module B.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
So i want when i press Item1 in Module A that in Module A is displayed progressbar that is animated and shows percentage of loading items from SQL witch code is in Module B...so when reading is finished in Module B progressbar goes to 100% and then Module B is started.
Sorry, I don't really understand.
Can you explain more in detail what exactly you want to do.
The PrograssBar is in ModuleA, the SQL reading is in ModuleB and where is the ListView?
Could you post a small project showing the problem.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
You talk about modules, so we assumed that they were code modules, but you seem to be talking about activities,veich is a completely different ballgame!
 
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
I will post example project here just a need a few minutes to write example and will replay soon here. thanks for helping me out
 
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
Here is example project...so when you press START button it needs to show circle progress bar that is refreshed and goes from 1% to 100% and when it reached 100% it needs to start second module.... this is example and i use in second module

'UPDATE - ArcProgressMaster in %
Main.Apm1.Progress = Round((i/(Cursor1.RowCount-1))*100)

But it does not update Apm1.Progress and it is not shows...Log(Round((i/(Cursor1.RowCount-1))*100)) gives me correct percetange.

Included is library needed to run this demo.... i did not write listview in second module because i would like to make it simple example to get you idea what i need to archive.

Thanks.
 

Attachments

  • TwoActivities.zip
    146.3 KB · Views: 303
  • circleprogressmaster.jar
    24.1 KB · Views: 289
  • circleprogressmaster.xml
    33.9 KB · Views: 426
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
I write above example just to add in first activity to read database and update progressbar every 6,25% of number of database items and then read from list from another activity...and for 8000 items it reads database and create listview for 4seconds..this is acceptable time...now i need to read bitmaps into list or arrays of bitmaps what is faster way? I try to add this into bitmaps of array using Dim bmpLogos(8000) As Bitmap but inserting into array takes me around 30seconds...witch is very slow approch...can some one have idea what will be faster way? Converting bitmap to string or binary and put to array and the read it binary or?

Here is code:

B4X:
Sub UpdateProgressBar
    File.Copy(File.DirAssets, "test.db", File.DirDefaultExternal, "test.db")
    File.Copy(File.DirAssets, "logos.db", File.DirDefaultExternal, "logos.db")

    'INITIALIZE - Movies DB
    SQLRead.SQL1.Initialize(File.DirDefaultExternal, "test.db", True)
 
    'INITIALIZE - Logos DB
    SQLRead.SQL2.Initialize(File.DirDefaultExternal, "logos.db", True)
 
    'QUERY - Categories
    SQLRead.Cursor1 = SQLRead.SQL1.ExecQuery("SELECT info_id, info_name FROM informations ORDER BY info_id ASC")


B4X:
SQLRead.List1.Initialize

Dim checkevery As Long
checkevery = Round((SQLRead.Cursor1.RowCount-1)*0.0625)

    'ADD - Channels
    For i=0 To SQLRead.Cursor1.RowCount-1
        'INCREMENT - Cursor1
        SQLRead.Cursor1.Position = i
     
        'QUERY - DB
        SQLRead.Cursor2 = SQLRead.SQL2.ExecQuery2("SELECT tvg_logo, png_logo FROM logos WHERE tvg_logo = ?", Array As String("nologo"))
     
        'SET - Position
        SQLRead.Cursor2.Position = 0
     
        'DECLARE - Buffers
        Dim Buffer() As Byte
     
        'READ - Bloob
        Buffer = SQLRead.Cursor2.GetBlob2(1)
     
        'DECLARE - InputStreams
        Dim InputStream1 As InputStream
     
        'INITIALIZE - InputStreams
        InputStream1.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
         
        'INITIALIZE - Bitmaps
        SQLRead.bmpChLogo(i).Initialize2(InputStream1)

        'CLOSE - InputStreams
        InputStream1.Close
     
        If (i Mod 500 = 1) Then
            Apm1.Progress = Round(i/(SQLRead.Cursor1.RowCount-1)*100)
            DoEvents
        End If
     
        SQLRead.List1.Add(SQLRead.Cursor1.GetString("info_name")) 
    Next
 
    CallSubDelayed(SQLRead, "ProgressBar")
End Sub



Sub btnStart_Click
    'SHOW - Apm1
    Apm1.Visible = True
    'CALL - SQL Read And Update ProgressBar
    UpdateProgressBar
End Sub

And Second Activity code:

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim SQL1, SQL2 As SQL
    'DEFINE - Cursors
    Dim Cursor1, Cursor2 As Cursor
    Dim List1 As List
    Dim bmpChLogo(8000) As Bitmap
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim lvTest As ListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    lvTest.Initialize("lvTest")
    Activity.AddView(lvTest, 0, 0, 250dip, 800dip)
End Sub

Sub Activity_Resume
 
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub ProgressBar
    For i=0 To List1.Size-1
        lvTest.AddSingleLine(List1.Get(i))
    Next
End Sub

So reading strings from database needs 3seconds and generating from second activity needs 1seconds (this is for 8000items), but how to add to array bitmaps and then read it in second activity to be time around 2- 3 seconds or lower?


It is shame that android cannon use from second activity ListView component because i want to do this:

Second activity:

Sub Process_Globals
Dim lvTest As ListView
End Sub

First activity:

Sub Activity_Create(FirstTime As Boolean)
SecondActivity.lvTest.AddSingleLine("Test")
End Sub

Can this be done another way?
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
Second activity:

Sub Process_Globals
Dim lvTest As ListView
End Sub

First activity:

Sub Activity_Create(FirstTime As Boolean)
SecondActivity.lvTest.AddSingleLine("Test")
End Sub
This cannot be done, that's how Android works.
Sorry, but I still don't undestand your logic!
It is difficult to help without knowing exactly what you want to do.
You post an example project not showing what you explain, then you send code snippets changing the original project.
Why don't you post a project with all the code you posted !?

What exactly do you want to do in the second Activity ?
Why do you not call the second Activity whith the ProgressBar and do everything in the second Activity.

By the way, SQL1 should be declared and initialized in the Starter Service!
 
Upvote 0
Top