Erreur startForeground après la mise à jour vers Android 8.1 : l'application plante avec ForegroundServiceDidNotStartInTimeException
Bonjour à tous ! Je suis un développeur Android débutant en Kotlin. Après avoir mis à jour mon appareil vers Android 8.1 (Oreo), mon application a commencé à planter avec une erreur lors du démarrage d'un service d'arrière-plan. Avant, sur Android 7.0, tout fonctionnait parfaitement.
Voici mon code de service :
```kotlin
class MyForegroundService : Service() {
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
val notification = Notification.Builder(this, "my_channel")
.setContentTitle("Le service fonctionne")
.setContentText("Téléchargement en cours...")
.setSmallIcon(R.drawable.ic_notification)
.build()
startForeground(1, notification)
// ... tâche longue en arrière-plan
return START_STICKY
}
override fun onBind(intent: Intent?): IBinder? = null
}
```
Et voici comment je démarre le service depuis l'Activity :
```kotlin
startService(Intent(this, MyForegroundService::class.java))
```
L'erreur dans les logs : `android.app.ForegroundServiceDidN