how to pass data from broadcast to service?

情到浓时终转凉″ 提交于 2019-12-13 04:07:21

问题


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();
}

回答1:


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



来源:https://stackoverflow.com/questions/8522447/how-to-pass-data-from-broadcast-to-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!