import android.app.Service;import android.content.Intent;import android.os.Binder;import android.os.IBinder;import android.util.Log;publicclassMyServiceextendsService{public String state ="running";public MyBinder myBinder =newMyBinder();publicMyService(){}@Overridepublic IBinder onBind(Intent intent){// TODO: Return the communication channel to the service.
Log.i("service_life","OnBind function 绑定服务成功!");
state ="bind_service";return myBinder;}@OverridepublicbooleanonUnbind(Intent intent){
Log.i("service_life","OnUnBind function 解除绑定成功!");
state ="onUnBind";returnsuper.onUnbind(intent);}@OverridepublicvoidonDestroy(){
Log.i("service_life"," onDestroy function 销毁服务!");
state ="onDestroy";super.onDestroy();}@OverridepublicvoidonCreate(){
Log.i("service_life","on Create function 开启服务!");
state ="onCreate";super.onCreate();}publicclassMyBinderextendsBinder{public String getState(){return state;}}}