I want to pass string from fragments to service. i tried by setvalue and bind but it works with activity not with startservice right?
and what is "ServiceConnection" and by using ServiceConnection is it possible to pass string?
here is my fragment code to start service.
I have change my code to this and it works perfect
Intent intent = new Intent(getActivity(), myPlayService.class);
Bundle b = new Bundle();
b.putString("link", "http://94.23.154/bbc");
intent.putExtras(b);
getActivity().startService(intent);
and in service i used
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub
if(intent != null){
Bundle bundle = intent.getExtras();
link = bundle.getString("link");
}
You can pass string from Fragment to Service via Intent and using the
putExtra()method:In the Service you will retrieve the string in
onStartCommand():