停止通过startService()方式启动的service的两种方法

来源:互联网 发布:css3动画和js动画 编辑:程序博客网 时间:2024/04/30 18:49

stopService()和stopSelf()都可以停止通过startService()方式启动的service。

stopService需要传递startService(Intent service)时的intent对象作为参数,停止此intent对应的service。

stopSelf直接停止本service,不需要参数,在service中直接调用即可。

service退出时会调用onDestroy()函数,可以在此函数中进行释放等操作。例如执行MediaPlayer对象的release()并赋值为null,调用System.exit(0);退出应用程序等。

原创粉丝点击