Error startForeground after updating to Android 8.1: how to fix?
Hello everyone! I'm developing an app in Kotlin that uses a background service for location tracking. After updating my device to Android 8.1 (Oreo), my service stopped working and crashes with the error `Context.startForegroundService() did not then call Service.startForeground()`. Here's my service code:
```kotlin
class LocationService : Service() {
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
val notification = NotificationCompat.Builder(this, "channel_id")
.setContentTitle("Service active")
.setContentText("Location tracking")
.setSmallIcon(R.drawable.ic_location)
.build()
startForeground(1, notification)
return START_STICKY
}
override f
No answers yet.
Log in to leave an answer
Blogs
C# Application Performance Optimization: Best Practices for .NET
How to Write a REST API in Rust in 30 Minutes: A Step-by-Step Guide
Serverless Functions in Kotlin: AWS Lambda — Complete Guide
Caught NetworkOnMainThreadException in 2025? Complete Guide to Fixing It in Java