问题
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