android - How to perform multiple related calls to AsyncTasks without overlapping? -
I have an application that needs to call repeatedly for web API, effectively, this SQL table Repeats according to the record and makes a unique call to the web server with appropriate data. This is a kind of data synchronization
As I understand when requesting this kind of HTTP request for an API, this UI should be within an AsyncTask to avoid hanging, so I Your AsyncTask class has made a request that parses back and parses feedback, but I need to back this data into the calling class.
Above him, I do not want calling classes to run these requests in parallel. I want to make this a request, and do not want to repeat the next record in the table and the second request should not be made until the first request ends. So in a way, I want to block it, but still in a different thread, so that the UI is not static. At least, I think that's what I want.
Pseudo code is something on the lines of this:
// caller function synchronize public null () {Load all records from SQL table for each record: if Record type is X: new asyncX (). Execute (records) // After this successfully completes, // I want to do something with the return value here, // before going to the next recurrence // when some UI here, // some nice spine Show logo and possibly // some text // if the record type is Y: new asyncY (). Execute (records) // Like the above // // async class public class asyncTask in AsyncX and lt; RecordType, Zero, Record Type and gt; {Type secure recordindexgrounds (record type ... records) {Jason Make HTTP response to HTML response parsing response Return record}} The way I'm thinking of doing this, change it The synchronized function to run a record at once, call the async function, and finish, and then return the async function back to the synchronize_followup () function which returns that return Need to be done with the price, and then syncs back again again, but I'm not sure I like it.
How to consider moving forward?
The way you want to handle it has already been invented with threading synchronization , So you implement it your way.
Semaphore is a class similar to CountDownLatch name. When you declare an object, and activate the lock mechanism through .wait () , you do not issue a .countdown () statement By doing so, it will stabilize and execute code. Actually, if you can declare , then perhaps that effect will be seen by you. This is a good example of how to prevent a thread execution based on the execution of another.
Comments
Post a Comment