# ServiceLifecycleDispatcher

Artifact: [androidx.lifecycle:lifecycle-service](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/ServiceLifecycleDispatcher.kt+class:androidx.lifecycle.ServiceLifecycleDispatcher) Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.0.0)

*** ** * ** ***

<br />

```
public class ServiceLifecycleDispatcher
```

<br />

*** ** * ** ***

Helper class to dispatch lifecycle events for a Service. Use it only if it is impossible to use `https://developer.android.com/reference/androidx/lifecycle/LifecycleService`.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/lifecycle/ServiceLifecycleDispatcher#ServiceLifecycleDispatcher(androidx.lifecycle.LifecycleOwner)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner provider)` |

| ### Public methods |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/Lifecycle` | `https://developer.android.com/reference/androidx/lifecycle/ServiceLifecycleDispatcher#getLifecycle()()` `https://developer.android.com/reference/androidx/lifecycle/Lifecycle` for the given `https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner` |
| `void` | `https://developer.android.com/reference/androidx/lifecycle/ServiceLifecycleDispatcher#onServicePreSuperOnBind()()` Must be a first call in `https://developer.android.com/reference/android/app/Service.html#onBind(android.content.Intent)` method, even before super.onBind call. |
| `void` | `https://developer.android.com/reference/androidx/lifecycle/ServiceLifecycleDispatcher#onServicePreSuperOnCreate()()` Must be a first call in `https://developer.android.com/reference/android/app/Service.html#onCreate()` method, even before super.onCreate call. |
| `void` | `https://developer.android.com/reference/androidx/lifecycle/ServiceLifecycleDispatcher#onServicePreSuperOnDestroy()()` Must be a first call in `https://developer.android.com/reference/android/app/Service.html#onDestroy()` method, even before super.OnDestroy call. |
| `void` | `https://developer.android.com/reference/androidx/lifecycle/ServiceLifecycleDispatcher#onServicePreSuperOnStart()()` Must be a first call in `https://developer.android.com/reference/android/app/Service.html#onStart(android.content.Intent, int)` or `https://developer.android.com/reference/android/app/Service.html#onStartCommand(android.content.Intent, int, int)` methods, even before a corresponding super call. |

## Public constructors

### ServiceLifecycleDispatcher

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.0.0)

```
public ServiceLifecycleDispatcher(@NonNull LifecycleOwner provider)
```

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner provider` | `https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner` for a service, usually it is a service itself |

## Public methods

### getLifecycle

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.0.0)

```
public @NonNull Lifecycle getLifecycle()
```

`https://developer.android.com/reference/androidx/lifecycle/Lifecycle` for the given `https://developer.android.com/reference/androidx/lifecycle/LifecycleOwner`

### onServicePreSuperOnBind

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.0.0)

```
public void onServicePreSuperOnBind()
```

Must be a first call in `https://developer.android.com/reference/android/app/Service.html#onBind(android.content.Intent)` method, even before super.onBind call.

### onServicePreSuperOnCreate

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.0.0)

```
public void onServicePreSuperOnCreate()
```

Must be a first call in `https://developer.android.com/reference/android/app/Service.html#onCreate()` method, even before super.onCreate call.

### onServicePreSuperOnDestroy

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.0.0)

```
public void onServicePreSuperOnDestroy()
```

Must be a first call in `https://developer.android.com/reference/android/app/Service.html#onDestroy()` method, even before super.OnDestroy call.

### onServicePreSuperOnStart

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.0.0)

```
public void onServicePreSuperOnStart()
```

Must be a first call in `https://developer.android.com/reference/android/app/Service.html#onStart(android.content.Intent, int)` or `https://developer.android.com/reference/android/app/Service.html#onStartCommand(android.content.Intent, int, int)` methods, even before a corresponding super call.