Android Question Zip in service blocks activity

Nickelgrass

Active Member
Licensed User
Longtime User
Hi,
its a simple thing that I cant get to work :(

I have an activity and a service. The service simply zips a folder to a nother folder

B4X:
#Region  Service Attributes
    #StartAtBoot: False
#End Region

Sub Process_Globals
End Sub

Sub Service_Create
End Sub

Sub Service_Start (StartingIntent As Intent)
    Dim zip As ABZipUnzip
    zip.ABZipDirectory("somefolder", "someotherfolder/zipfile.zip")
    StopService("")
End Sub

Sub Service_Destroy
End Sub

The problem is that also my activity hangs. I get prompted all the time that it is not responding and if it should get closed. How can the service affect my activity. I need to zip large folders so it takes some time.

This is all my activity does
B4X:
Sub Process_Globals
    Dim tim As Timer
    Dim cn As Int
End Sub

Sub Globals
    Private Label1 As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("main")
    tim.Initialize("tim", 1000)
    tim.Enabled = True
    If IsPaused(zipservice) Then StartService(zipservice)
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub tim_Tick
    Label1.Text = File.Size("someotherfolder", "zipfile.zip") & "  " & cn
    cn = cn + 1
End Sub

Whats going on here???

Thanks!
 

Troberg

Well-Known Member
Licensed User
Longtime User
I suspect that the problem is that the service, while having a different Life cycle, does not run in it's own thread. In this case, I think you'll have to dive into the threading library to avoid 'Application not responding'.
 
Upvote 0
Top