android-service
service 不是单独的一个线程
注册service
<service android:name= ".FirstService" ></service>
启动service
Intent intent = new Intent();
intent.setClass(MainActivity. this,FirstService. class);
startService(intent);
onCreate()---> onStartCommand)()
终止service
Intent intent = new Intent();this,FirstService. class);intent.setClass(MainActivity.stopService(intent);服务不能自己运行,需要通过调用Context.startService()或Context.bindService()方法启动服务。这两个方法都可以启动Service,但是它们的使用场合有所不同。使用startService()方法启用服务,调用者与服务之间没有关连,即使调用者退出了,服务仍然运行。使用bindService()方法启用服务,调用者与服务绑定在了一起,调用者一旦退出,服务也就终止,大有“不求同时生,必须同时死”的特点。