如何从广播数据传递给服务? [英] how to pass data from broadcast to service?

查看:181
本文介绍了如何从广播数据传递给服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好家伙任何一个可以告诉我如何从撒施发送数据服务以及如何接收服务类这里面的数据,因为它剂量不和我一起工作shuld我接受它里面((onStartCommand))或((在onStart ))或内侧((的onReceive))
和我应该在Maninafest做

 字符串数据=你好;
意图int​​ent1 =新意图(背景下,Myservice.class);
    intent1.putExtra(数据,数据);
    context.startService(intent1);//当我收到来自广播数据公众诠释onStartCommand(意向意图,诠释标志诠释startId){
字符串数据=;
数据= intent.getStringExtra(手机);
Toast.makeText(这一点,这里是你的数据+数据,Toast.LENGTH_LONG).show();
}


解决方案

更换
数据= intent.getStringExtra(手机);
数据= intent.getStringExtra(数据);

hello guys can any one tell me how to send data from broad cast to service and how to receive this data inside the service class because it dose not work with me shuld i receive it inside ((onStartCommand)) or ((onStart)) or inside ((onReceive)) and what i should do in the Maninafest

String data="hello";
Intent intent1=new Intent(context,Myservice.class);
    intent1.putExtra("Data",data);
    context.startService(intent1);

//when i receive data from broad cast

public int onStartCommand(Intent intent, int flags, int startId) {
String data="";
data=intent.getStringExtra("Phone");
Toast.makeText(this,"here is your data"+data, Toast.LENGTH_LONG).show();
}

解决方案

replace data=intent.getStringExtra("Phone"); to data=intent.getStringExtra("Data");

这篇关于如何从广播数据传递给服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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