Android 启动意向服务

Android 启动意向服务,android,android-intentservice,Android,Android Intentservice,我通过以下方式启动意向服务: Intent MyIntentService = new Intent(this, clsMyIntentService.class); MyIntentService.putExtra("Command", Command1); startService(MyIntentService ); .... Sleep and do some work .... Intent MyIntentService = new Intent(this, clsMyInten

我通过以下方式启动意向服务:

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之前接收(就在之前)


有什么帮助吗?

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

查看这些链接以了解更多信息:

您似乎正在阻止UI线程,您能否发布更多关于“睡眠和做一些工作”的代码?之前的代码正在服务中运行,因此它不应该阻止UI。无论如何,被调用的IntentService不依赖于UI,对吗?仅供参考,服务在UI线程上运行,甚至IntentService,但在这种情况下,工作被分派到工作线程。哦,不知道。我以为服务是独立的。那么,有什么帮助吗?我理解延迟的原因,但是为什么顺序会改变呢?可能是您造成了消息队列的混乱。如果你有长时间的操作,你需要重新设计你的应用程序。