I have my main activity that start a service (Location service) and I want that service to broadcast the new location each time a new location is found.
Thanks to th
In your LocationService
, send local broadcast using:
Intent intent = new Intent(CMBroadcastReceiver.RECEIVE_LOCATION_UPDATE);
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
<service android:name=".LocationService" android:process=":location_service" />
Your service is in a separate process from the activity. LocalBroadcastManager
is only for use in one process. Either remove android:process
from the <service>
, or use some IPC mechanism (e.g., system broadcasts, properly secured).
LocalBroadcastManager
does not work across processes. Your Service
is running in a separate process.
You can either run your Service
in the same process as the Activity
- by removing the process
attribute from the <service>
element - or use some sort of IPC instead - e.g., by sending and receiving the broadcasts on a Context
instead of LocalBroadcastManager
.