Android:intentservice,如何中止或跳过handleintent队列中的任务

编程入门 行业动态 更新时间:2024-10-10 13:13:16
本文介绍了Android:intentservice,如何中止或跳过handleintent队列中的任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个调用意图服务(DownloadService")的活动(ApplicationActivity")

i have an activity ("ApplicationActivity") that call an intent service ("DownloadService")

intentService 在后台从互联网下载文件,但我希望能够中止特定的下载............

The intentService download files from internet in background, but i want to be able to abort a specific download.........

假设我将 5 个文件放入队列中:文件 1、2、3、4、5

So let's say that i put 5 files in queue: file 1,2,3,4,5

intent 服务开始下载数字 1,然后是第二个,依此类推....1)有没有办法在方法句柄事件中告诉意图服务中止你正在做的事情(在这种情况下是下载文件1)并开始下载下一个?

The intent service start downloading the number 1, then the second and so on.... 1) Is there a way to say to the intent service abort what you are doing at the moment in the method handle event (in this case downloading file 1) and start downloading the next one?

2)是否可以从队列中删除元素,例如在下载文件1时,将文件4从队列中删除,以便在数字3之后直接进入5?

2)Is it possible to remove element from the queue, so for example while is downloading file 1, remove the file 4 from the queue so that after the number 3 it goes straight to the 5?

简而言之,我需要一种与队列通信的方法来执行这两个简单的操作,但我在互联网上没有发现任何有用的东西:(

Shortly, i need a way to comunicate with the queue to perform these 2 simple operations, but i didn't find nothing usefull on internet :(

Tnx

推荐答案

我创建自己的 MyIntentService 类,复制非常短的原始类并为我自己的目的修改方法........特别是出队在我的情况下,您可以使用 ServiceHandler 方法的元素mServiceHandler.removeMessages(appId);删除消息队列中带有特定代码what"的任何待处理消息帖子,这意味着您必须标记添加到队列中的每条消息,并在每条消息的what"字段内添加一个标识符........例如

I create my own MyIntentService class copying the original one that is pretty short and modifying methods for my own purpose........in particular to dequeue an element you can use methods of ServiceHandler in my case mServiceHandler.removeMessages(appId); that Remove any pending posts of messages with a certain code 'what' that are in the message queue, this means that you have to label each message you add in the queue adding an identifier inside the "what" field of each message.....for example

public void onStart(Intent intent, int startId) { super.onStart(intent, startId); Message msg = mServiceHandler.obtainMessage(); msg.arg1 = startId; msg.obj = intent; msg.what = intent.getIntExtra("appId", 0); \parameters that come from the outside

更多推荐

Android:intentservice,如何中止或跳过handleintent队列中的任务

本文发布于:2023-11-13 04:32:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1583437.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:队列   跳过   Android   intentservice   handleintent

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!