main

square/leakcanary

Last updated at: 29/12/2023 09:39

LeakingService.kt

TLDR

This file defines a LeakingService class that extends the Service class. The LeakingService class overrides the onCreate() and onBind() methods.

Classes

LeakingService

The LeakingService class extends the Service class and is used to handle background operations. In the onCreate() method, it adds the LeakingService instance to a list of leaked services in the ExampleApplication class. It then stops the service immediately using stopSelf(). The onBind() method is overridden and returns null, indicating that the service does not support binding.

package com.example.leakcanary

import android.app.Service
import android.content.Intent
import android.os.IBinder

class LeakingService : Service() {

  override fun onCreate() {
    super.onCreate()
    (application as ExampleApplication).leakedServices += this
    stopSelf()
  }

  override fun onBind(intent: Intent?): IBinder? {
    return null
  }
}