保证context.startService()调用由以相同的顺序服务中获得性,他们被送到? [英] Are context.startService() calls guaranteed to be aquired by the service in the same order they were sent?
问题描述
是context.startService()调用保证通过他们被送到了相同的顺序服务中获得性?
考虑活动:
意图意图;意图=新意图(MyIntents.ADD_BATCH_ACTION);
intent.putExtra(MyIntents.BATCH_ACTION_NAME,烤甜甜圈);
startService(意向);意图=新意图(MyIntents.ADD_BATCH_ACTION);
intent.putExtra(MyIntents.BATCH_ACTION_NAME,做一个咖啡);
startService(意向);意图=新意图(MyIntents.ADD_BATCH_ACTION);
intent.putExtra(MyIntents.BATCH_ACTION_NAME,取咖啡和甜甜圈房间12);
startService(意向);startService(新意图(MyIntents.FLUSH_ADDED_ACTIONS));
有些动作可以大大的hve共同的工作,我可以优化服务如果我是确保它们在批处理执行。
我可以假设,服务onStartCommand会以相同的顺序来执行?
问候,托梅克
是context.startService()调用保证通过他们被送到了相同的顺序服务中获得性?
块引用>虽然我觉得他们碰巧才能发生,AFAIK这不是记录的行为,因此,我不会在指望它。
有些动作可以大大的hve共同的工作,我可以优化服务如果我是确保它们在批处理执行。
块引用>然后只调用
startService()
一次,在你的一批的一切。意向额外支持数组为多种类型,所以尽量包装额外的阵列,而不是只有一个。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
解决方案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.这篇关于保证context.startService()调用由以相同的顺序服务中获得性,他们被送到?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!