Android应用开发_学习笔记(18)
时间:2025-04-23
时间:2025-04-23
7、Service
1)创建Service
继承android.app.Service实现自己的服务
2)注册service
<service android:name="MyService"> </service>
3)启动service
startService(Intent service) ;
4)停止service
stopService(Intent service) ;
8、Service的生命周期
1)startService
①、service没有创建,则先调用onCreate方法,然后调用onStart方法。
②、service已经创建,则直接调用onStart方法。
2)stopService
调用onDestory最终销毁service。
上一篇:让眼神充满魅力(二)