将数据从活动发送到Intentservice [英] sending data from activity to Intentservice

查看:157
本文介绍了将数据从活动发送到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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆