2
I need to synchronize data between the server and client application on Android and for this I created several classes ASyncTask
, one synchronizes the Third Party, the other the Financial, Receivables and Payables, for example.
I did this to reuse code, which will be used in other services and activities.
However, the moment the user synchronizes the first time, on Activity
as ASyncTask
are executed one below the other, without checking whether the top has finalized the business rule.
My question is this, when a ASyncTask
is finished soon the bottom one is executed or starts before the ASyncTask
close the execution of?
The problem with this is occurring inconsistency in the Android database regarding the Foreign Keys for example when saving the records in Sqlite.
I didn’t know about this appeal, it was pretty cool. My only caveat is that SERIAL_EXECUTOR is only one and database tasks can be serialized with others that have no logical relation if another part of the program uses the same resource. I would prefer to be explicit, making each step schedule the next task. Decreases the chance of a change far from affecting the functioning.
– epx
@epx I don’t understand what you mean. In practical terms the
AsyncTask.SERIAL_EXECUTOR
does the same as what you propose in your reply.– ramaral
Let’s say it calls a method between scheduling task #1 and task #2. Then this method, which someone else did or will change, also uses the same trick to perform a handful of other serialized tasks.
– epx