问题
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