1e41f4b71Sopenharmony_ci# ServiceAbility Lifecycle
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ciYou can implement lifecycle callbacks (as described in the table below) in **service.js** or **service.ets**.  
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci**Table 1** ServiceAbility lifecycle callbacks
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci| API| Description| 
10e41f4b71Sopenharmony_ci| -------- | -------- |
11e41f4b71Sopenharmony_ci| onStart(): void | Called to initialize a ServiceAbility when the ServiceAbility is being created. This callback is invoked only once in the entire lifecycle of a ServiceAbility.| 
12e41f4b71Sopenharmony_ci| onCommand(want: Want, startId: number): void | Called every time a ServiceAbility is started on the client. You can collect calling statistics and perform initialization operations in this callback.| 
13e41f4b71Sopenharmony_ci| onConnect(want: Want): rpc.RemoteObject | Called when the ServiceAbility is connected.| 
14e41f4b71Sopenharmony_ci| onDisconnect(want: Want): void | Called when the connection to the ServiceAbility is disconnected.| 
15e41f4b71Sopenharmony_ci| onStop(): void | Called when the ServiceAbility is being destroyed. You should override this callback for your ServiceAbility to clear its resources, such as threads and registered listeners.| 
16