将数据从活动发送到Intentservice [英] sending data from activity to Intentservice
问题描述
我的需要是将活动中的数据发送到IntentService
my needs is to send data from activity to IntentService
(从扩展活动的类到扩展IntentService的类)
(from class that extends activity, to class that extends IntentService)
我通过使用BroadcastReciver成功发送了示例服务,但是我想扩展IntentService类而不是服务
i successed to send to sample service, by using BroadcastReciver, but i want to extend IntentService class and not service
有人知道我该怎么做吗?
someone know how can i do that?
来自
公共类MainActivity扩展了Activity {...}
public class MainActivity extends Activity { ... }
到
公共类MyIntentService扩展了IntentService {...}
public class MyIntentService extends IntentService { ... }
推荐答案
将数据放入与 startService()
调用一起使用的 Intent
附加内容中,以启动您的 IntentService
.然后, IntentService
可以在 onHandleIntent()
中读取更多内容.
Put the data in an Intent
extra that you use with the startService()
call to start your IntentService
. Then, the IntentService
can read that extra in onHandleIntent()
.
这篇关于将数据从活动发送到Intentservice的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!