У меня есть этот код:Android остановка IntentService не бегите в датчик близости
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_head_sound, container, false);
mButtonStartService=(ImageButton)rootView.findViewById(R.id.imageButton);
mButtonStartService.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(intent!=null)
{
getActivity().stopService(intent);
intent=null;
Log.d("intent","null");
}
else
{
intent=new Intent(getActivity(),MyIntentService.class);
getActivity().startService(intent);
}
}
});
return rootView;
}
Но IntentService не остановится и датчик приближения продолжает посылать значения в onSensorChanged().
Вам нужно будет показать нам код в вашем сервисе. –