I have a BroadcastReceiver that it will start a foreground service when the device reboots.
This is the code:
[BroadcastReceiver(Enabled = true, Exported = true)]
[IntentFilter(new[] { Intent.ActionBootCompleted })]
public class ActionBootCompletedBroadcastReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
if (intent.Action == Intent.ActionBootCompleted)
{
ServicioConfiguracion miServicioConfiguracion = new ServicioConfiguracion();
bool miBlMyParamter = miServicioConfiguracion.GetParameter();
if (miBlMyParameter == true)
{
var foreGroundServiceIntent = new Intent(Android.App.Application.Context, typeof(MyForegroundService));
Android.App.Application.Context.StartForegroundService(intent);
context.StartForegroundService(foreGroundServiceIntent);
}
}
}
}
And this is the code of the configuration manager that reads the value of configuration of the application:
public bool GetParameter()
{
return Preferences.Default.Get<bool>("MyParameter", false);
}
The problem is that it seems that the BroadCastReceiver can't get the value of the parameter, because if I comment the if that determinates if start the foreground service or not, it starts.
The other problem that I have it is I don't know how to debug the BroadcastReceiver, because when the device reboots, the debugger stops.
My idea is that the user can configure in the application if starts the foreground service or not when the device starts.
How could I get the values of configuration of the application in the BroadCastReceiver?
Thanks.