Reputation: 4586
Xamarin forms android application targeting api level 26 crashes with java.lang.IllegalStateException: Not allowed to start service Intent
when receiving notification in background.
From Notification in oreo, what i understood is only during the app whitelisted duration only the app can make services. How to properly handle this situvation, i call and update my databases when i receive notification, how can i properly manage this.
One answer shows
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
context.startForegroundService(new Intent(context, ServedService.class));
} else {
context.startService(new Intent(context, ServedService.class));
}
But how can i implement this in a xamarin forms application for properly receiving push notifications.
Upvotes: 0
Views: 4732
Reputation: 21043
Starting from Android 8.0 (API level 26) .
The startService() method now throws an IllegalStateException if an app targeting Android 8.0 tries to use that method in a situation when it isn't permitted to create background services.
Read Android 8.0 Behavior Changes for way around to make work in android Oreo. You can use Job scheduler on notification receive to perform database task .
Upvotes: 1