I have a Service
and BroadcastReceiver
in my application, but how do I launch the service directly from the BroadcastReceiver
? Using
startService(new Intent(this, MyService.class));
does not work in a BroadcastReceiver
, any ideas?
EDIT:
context.startService(..);
works, I forgot the context part
Demonstrates how to run an Android service in a separate process using a separate . so lib file, and how to communicate with Qt using a BroadcastReceiver. This example demonstrates how to create and run an Android service in a separate process that uses a separate .
In receiver, you can just put all params into a Bundle, and use startService(Intent) containing that bundle to call the target service. In service, you parse the bundle and get all params. This is a solution and it's works fine.
Broadcast in android is the system-wide events that can occur when the device starts, when a message is received on the device or when incoming calls are received, or when a device goes to airplane mode, etc. Broadcast Receivers are used to respond to these system-wide events.
It's always suggested to register and unregister broadcast receiver programmatically as it saves system resources.
Don't forget
context.startService(..);
should be like that:
Intent i = new Intent(context, YourServiceName.class); context.startService(i);
be sure to add the service to manifest.xml
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