ActivityNotFoundException while trying to start a service.

前端 未结 2 1317
悲哀的现实
悲哀的现实 2021-01-21 12:58

I am getting an Activity not found exception while trying to start a service. I have the service registered in the Manifest. Adding what I think is the relevant code and the Log

2条回答
  •  轮回少年
    2021-01-21 13:43

    your method startDrive is wrong

    private void startDrive()
    {
        Log.w("rakshak", "Start drive clicked");
    
        Intent intent = new Intent(getActivity(), GPSService.class);
        intent.setAction(util.START_DRIVE);
        getActivity().startActivity(intent);
    }
    

    you are using startActivity instead of startService. Also stopDrive() is starting the service again

提交回复
热议问题