Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

BroadcastReceiver - Can't Start Service on Boot | Reboot

$
0
0

Hello everyone,

I am facing problem to start background service on boot. My service runs without problems if started from anywhere else, but on boot, crashes immediately. Below is my BroadcastReceiver class;

namespace WSTests.Droid
{

    [BroadcastReceiver(Enabled = true)]
    public class BootComplete : BroadcastReceiver
    {
        public override void OnReceive(Context context, Intent intent)
        {
            try
            {
                if (intent.Action.Equals(Intent.ActionBootCompleted))
                {
                    Toast.MakeText(context, "Received intent!", ToastLength.Long).Show();
                    Intent i = new Intent(context, typeof(SimpleService));
                    i.AddFlags(ActivityFlags.NewTask);
                    context.StartActivity(i);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}

I have attached sample project as well for more details. I will appreciate for some help.


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>