I want to start service from fragment from a list view item. I am trying to call service with:
startService(new Intent(getActivity(),myPlayService.class));
But it wont work at all. How do i call my service from fragments? Is there any another way to start service?
Replace
startService(new Intent(getActivity(),myPlayService.class));
with
getActivity().startService(new Intent(getActivity(),myPlayService.class));
To start service from a fragment use
Java
requireActivity().startService(new Intent(getContext(), ServiceName.class));
Kotlin
requireActivity().startService(Intent(context, ServiceName::class.java)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With