IntentService中的队列大小是否有限制?

时间:2013-11-21 15:41:08

标签: android intentservice

我不太可能遇到任何可能存在的屋顶,但我可能会向IntentService发送大量意图。

我很想知道您可以向IntentService发送多少Intent的上限?队列有大小限制吗?我在文档中找不到任何关于此的内容。

提前致谢

2 个答案:

答案 0 :(得分:5)

tl;博士编号

来自android源码(API 19):

看起来IntentService只使用与帖子绑定的常规LooperHandler

当您使用新意图调用intent服务的start时,它只是将意图作为消息发送给处理程序。

@Override
public void onStart(Intent intent, int startId) {
    Message msg = mServiceHandler.obtainMessage();
    msg.arg1 = startId;
    msg.obj = intent;
    mServiceHandler.sendMessage(msg);
}

处理程序:

private final class ServiceHandler extends Handler {
    public ServiceHandler(Looper looper) {
        super(looper);
    }

    @Override
    public void handleMessage(Message msg) {
        onHandleIntent((Intent)msg.obj);
        stopSelf(msg.arg1);
    }
}

Looper使用的HandlerMessageQueue,但没有可添加到其中的最大项目数。

答案 1 :(得分:1)

理论上没有限制,但应用程序可能会耗尽内存,具体取决于传入的数据大小。