Android Question Service locking activity

advansis

Active Member
Licensed User
Longtime User
Hi guys,
I wrote a service that starts each minute by calling 'StartServiceAt' (at the end of each Service_Start routine).
It must manage a long process: it must parse big data coming from a web-service (about 1-2Mb).
The Service_Start routine calls the parsing one, inside there's a loop that works for about 2-3 minutes; during this loop the service-start time is delayed.

The first problem is:

During the running of the loop, the user interface hangs (activities take about 10 seconds to load) and sometimes the screen gets blank. Android, also tries to kill my application (asks me...)

What I've tried:
1) Set the attribute: #StartCommandReturnValue: android.app.Service.START_STICKY
2) Put a 'DoEvents' statement inside the loop (BetterDialogs' inputbox by Informatix won't work in this case: dialogs are closed automatically after loaded...)
3) Created 2 services, one catching HttpUtils2 JobDone events and the other parsing the results each minute
4) Did a prayer :)

but nothing seems to work.
After exiting from the loop, the application runs normally.

The second problem is: during the loop I cannot refresh the UI because timer's tick are not fired...

Any clue ? Thanks in advance.


G. Pizzuto
 

advansis

Active Member
Licensed User
Longtime User
Thanks for replying...
Before your answer, I tought services were called in separate threads from the UI. So I'll give a try.
Is there some basic approach in b4a or shell I use the threading library provided from agraham ?
 
Upvote 0

advansis

Active Member
Licensed User
Longtime User
I get data through HttpUtils2 and SaxParser. Then I use Sql library to insert the data inside my db (a FOR cycle with UPDATE and INSERT statements).
Both Receiving and Db-Inserts are done inside a service (running each minute, HttpUtils saves it's data in a global string).
 
Upvote 0

advansis

Active Member
Licensed User
Longtime User
Sax is very fast, as data are very simple. The long process is the one performing the 'UPSERT' in the db (update or insert dipending on the existance of the record or not). Anyway I'm trying agraham's library. Still writing. Tanks a lot.
 
Upvote 0

advansis

Active Member
Licensed User
Longtime User
The agraham's library is not working for me... Cannot start the thread because of "Exception : wrong number of arguments; expected 3, got 0".
As I understand, it's an unresolved problem (and Erel gets angry each time someone talks about threadings...)
So, is there a simple library to manage very simple threads (neither arguments nor semaphores) ?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
have you tried to wrap sql-insert into a begintransaction/endtransaction?

B4X:
Sub InsertManyRows
    SQL1.BeginTransaction
    Try
        For i = 1 To 500
            SQL1.ExecNonQuery2("INSERT INTO table1 VALUES ('def', ?, ?)", Array As Object(i, i))
        Next
        SQL1.TransactionSuccessful
    Catch
        Log(LastException.Message)
    End Try
    SQL1.EndTransaction
End Sub
 
Upvote 0

advansis

Active Member
Licensed User
Longtime User
Yes, I did after your post. Seems to be more responsive, probably i must check all over the code...
 
Upvote 0
Top