0

我以这种方式启动 Intent 服务:

Intent MyIntentService = new Intent(this, clsMyIntentService.class);
MyIntentService.putExtra("Command", Command1);
startService(MyIntentService );

....
Sleep and do some work
....

Intent MyIntentService = new Intent(this, clsMyIntentService.class);
MyIntentService.putExtra("Command", Command2);
startService(MyIntentService );

我的问题是 IntentService 在一切都完成之前不会收到任何东西。并且当它开始接收命令时是错误的,因为 Command2 比 Command1 更早被接收(就在之前)。

有什么帮助吗?

4

1 回答 1

0

将您的服务实现为IntentService类型,它有自己的工作线程以避免阻塞 UI,并将请求排队以启动它,因此您的命令将以正确的顺序执行。

检查这些链接以获取更多信息:http: //developer.android.com/reference/android/app/IntentService.html https://developer.android.com/training/run-background-service/create-service.html

于 2015-01-18T13:47:49.273 回答