Are context.startService() calls guaranteed to be aquired by the service in the same order they were sent?

六月ゝ 毕业季﹏ 提交于 2019-12-25 08:23:37

问题


Are context.startService() calls guaranteed to be aquired by the service in the same order they were sent?

consider in activity:

Intent intent;

intent = new Intent(MyIntents.ADD_BATCH_ACTION);
intent.putExtra(MyIntents.BATCH_ACTION_NAME, "Bake donuts");
startService(intent);

intent = new Intent(MyIntents.ADD_BATCH_ACTION);
intent.putExtra(MyIntents.BATCH_ACTION_NAME, "Make a coffee");
startService(intent);

intent = new Intent(MyIntents.ADD_BATCH_ACTION);
intent.putExtra(MyIntents.BATCH_ACTION_NAME, "Fetch coffee and donut to room 12");
startService(intent);

startService(new Intent(MyIntents.FLUSH_ADDED_ACTIONS));

Some action can hve much common work, I could optimize service if i were sure that they are executed in a batch.

Can I assume that service onStartCommand would be executed in the same order ?

regards, Tomek


回答1:


Are context.startService() calls guaranteed to be aquired by the service in the same order they were sent?

While I think they happen to occur in order, AFAIK this is not documented behavior, and therefore I would not count upon it.

Some action can hve much common work, I could optimize service if i were sure that they are executed in a batch.

Then only call startService() once, with everything in your "batch". Intent extras support arrays for many types, so try packaging an array of extras instead of just one.



来源:https://stackoverflow.com/questions/10030846/are-context-startservice-calls-guaranteed-to-be-aquired-by-the-service-in-the

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!