I am trying to make a simple service which starts with device boot. Thing is that device return message "Unfortunately, [app_name] has stopped."
I am struggling with this problem from few hours, with looking for mistake, but it is too simple.. Hope, you guys can help me with this problem.
This is my code:
AndroidManifest.xml
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application android:allowBackup="true" android:label="@string/app_name">
<receiver android:name=".StartReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<service android:name=".PService" />
</application>
StartReceiver.cs
[BroadcastReceiver]
[IntentFilter(new[] { Intent.ActionBootCompleted })]
public class StartReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
Intent startIntent = new Intent(context, typeof(PService));
context.StartService(startIntent);
}
}
and lastly PService.cs
[Service]
public class PService : Service
{
public override void OnCreate()
{
base.OnCreate();
}
public override IBinder OnBind(Intent intent)
{
return null;
}
public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
{
Toast.MakeText(this, "Start", ToastLength.Short).Show();
return StartCommandResult.Sticky;
}
public override void OnDestroy()
{
base.OnDestroy();
Toast.MakeText(this, "Stop", ToastLength.Short).Show();
}
}
Additional this service application is targetted to API 19 (4.4.2 KitKat) Android version.
I think there will be really small mistake, made by me but truly I cant find it out.. Thanks in advance for any help.