ActivityNotFoundException while trying to start a service.

前端 未结 2 1297
悲哀的现实
悲哀的现实 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

    0 讨论(0)
  • 2021-01-21 13:57

    GPSService is a service. It is not an Activity. You cant do as

     getActivity().startActivity(intent);
    

    instead of do startService(intent);

    For more information refer Docs

    0 讨论(0)
提交回复
热议问题