gpt4 book ai didi

android 有多少 Intent 服务可以并行运行

转载 作者:行者123 更新时间:2023-12-05 04:12:19 24 4
gpt4 key购买 nike

我有多个 IntentService 的子类。谁能告诉我有多少这样的 Intent 服务可以并行运行。谢谢

最佳答案

IntentService 如果来自同一个类,则不会并行运行。它们将按顺序运行。换句话说,如果您有一个名为 DownloadServiceIntentService 从给定的 URL 下载文件,那么您可以像这样运行它:

List<String> downloadUrls = getDownloadUrls();
Context ctx = getContext();
Intent baseIntent = new Intent(ctx, DownloadService.class);
for(String url : downloadUrls) {
Intent downloadService = new Intent(baseIntent);
downloadService.putString("downloadUrl", url);
ctx.startService(downloadService);
}

DownloadService 会启动一次。然后,第一个 URL 将被传递给它,它就会开始下载。然后,完成后DownloadService 将使用第二个 url。然后是第三个,依此类推。这一切都按顺序运行。

现在,您可以有第二个名为 UploadServiceIntentService,它同样会将文件上传到给定的 URL。如果您使用不同的参数多次启动它,它也会按顺序运行到每个调用。 但是,它将与DownloadService 并行运行,因为它们是两个独立的Service

编辑:至于数量限制。我确定有一个,但您可能会在到达它之前用完内存(或者认为一百种不同的服务不是做事的最佳方式)。

关于android 有多少 Intent 服务可以并行运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40865016/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com