I just wonder whether there will be any conflict if two service intents are sent to the same service at the same time. My code is as below:
public static class UpdateService extends Service {
@Override
public void onStart(Intent intent, int startId) {
int widgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
UpdateThread updateThread = new UpdateThread();
updateThread.mWidgetId = widgetId;
updateThread.mContext = this;
updateThread.start();
stopSelf();
}
}
Suppose there are two intents, intent 1 and intent 2, for UpdateService at the same time. As I understand, there will be only one UpdateService instance. Then, will the two intents cause the service code to run sequentially like the workflow below?
- UpdateService starts, i.e. onStart() is called, for intent 1.
- UpdateService stops because stopSelf() is called in onStart().
- UpdateService starts, i.e. onStart() is called, for intent 2.
- UpdateService stops because stopSelf() is called in onStart().
Could the two intents cause the service code, i.e onStart(), to run simultaneously? Do I need to put synchronized in the onStart() method definition?
Thanks.