开启服务和绑定服务的区别/优缺点
开启服务:startService() → stopService()(其生命周期为onCreate() → onStartCommand() → onDestroy())
绑定服务:bindService() → unBindService()(其生命周期为onCreate() → onBind() → onUnbind() → onDestroy())
区别:startService()可以长期在后台运行,bindService()不可以在后台长期运行;bindService()启动服务可以跟服务进行通讯,startService()启动服务不可以跟服务进行通讯。
解决方法:混合两种启动方式,先startService()再bindService(),这样又可以长期运行又可以跟服务进行通讯。