Home Queue messages for async processing
Reply: 0

Queue messages for async processing

user991
1#
user991 Published in June 23, 2018, 9:24 pm

Im receiving list of messages asynchronously from server push api. I need to do some long running work for each messages. Currently im using async task for that.

In my current implementation in creating new async task every time I receive messages. I have noticed that on older devices, im running like five async task in same time (I think they are queued). This does not sound very efficient for mew.

public class MyFragment extends Fragment {

    // Called when server pushes new messages
    private void messagesReceived(List<MyMessage> newMessages) {
        new MyMessageProcessorAsyncTask(newMessages) {
            @Override
            public void onPostExecute(List<MyProcessedMessage> messages) {
                // Update ui
            }
        }.execute();
    }
}

What is typically the best way to handle this kind of queue for async processing and how many async operations I should run in same time?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.321942 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO