My BroadcastReceiver seems to not be receiving the intent it is listening for.
I'm starting a background service which has to run all the time. Whenever the service is killed it sends an intent to my BroadcastReceiver which then restarts the service.
Here's the onDestroy
of my service:
@Override
public void onDestroy() {
Log.i(TAG, "onDestroy");
sendBroadcast(new Intent("com.myapp.app.RESTART_SERVICE"));
stoptimertask();
super.onDestroy();
}
Here's my BroadcastReceiver:
public class RestarterBroadcastReceiver extends BroadcastReceiver {
public RestarterBroadcastReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "Service stopped, restarting...");
context.startService(new Intent(context, ActivityRecognitionService.class));
}
}
And the important bit of the Android Manifest:
<receiver
android:name=".RestarterBroadcastReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.myapp.app.RESTART_SERVICE"/>
</intent-filter>
</receiver>
Why isn't my BroadcastReceiver receiving the intent?