大家好,任何人都可以告诉我如何将数据从广播发送到服务以及如何在服务类中接收这些数据,因为它不能与我合作shuld我收到它((onStartCommand))或((onStart) ))或内部((onReceive)) 以及我应该在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();
}
答案 0 :(得分:2)
替换
data=intent.getStringExtra("Phone");
到data=intent.getStringExtra("Data");