简体   繁体   English

Android:将广播接收器转变为服务

[英]Android: Turning a Broadcast receiver into a service

Thanks to a good bit of help I got from someone in my last question I am further ahead then before. 多亏了我在上一个问题中得到某人的帮助,我才比以前更领先。 Now I need to figure out how make this broadcast into a service. 现在,我需要弄清楚如何将此广播转换为服务。 Or do I need to make a 3rd file and make a service out of that class? 还是我需要制作第3个文件并在该类之外提供服务?

Any help would be cool! 任何帮助都将很酷!

create a class which extends Service. 创建一个扩展Service的类。

public class myService extends Service{

and use the Application Context object passed to your BroadcastReceiver to start the service. 并使用传递给BroadcastReceiver的Application Context对象启动服务。

context.startService(intent);

If you need to carry data over from your Intent object put a set of extras into the Intent object you create when you call 如果您需要从Intent对象继承数据,请在调用时创建的Intent对象中放一些额外的东西

sendBroadcast(Intent intent);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM