public void OnServiceDisconnected(ComponentName name) { Log.Debug(TAG, $"OnServiceDisconnected {name.ClassName}"); IsConnected = false; Binder = null; timestampActivity.UpdateUiForUnboundService(); }
/// <summary> /// 有客户端(某个Activity)连接上时会调用此方法 /// </summary> /// <param name="name"></param> /// <param name="service"></param> public void OnServiceConnected(ComponentName name, IBinder service) { Binder = service as TimestampBinder; IsConnected = this.Binder != null; string message = "onServiceConnected - "; Log.Debug(TAG, $"OnServiceConnected {name.ClassName}"); if (IsConnected) { message = message + " bound to service " + name.ClassName; //服务的名字 timestampActivity.UpdateUiForBoundService(); } else { message = message + " not bound to service " + name.ClassName; timestampActivity.UpdateUiForUnboundService(); } Log.Info(TAG, message); timestampActivity.timestampMessageTextView.Text = message; }
/// <summary> /// 绑定客户端TimestampActivity /// </summary> /// <param name="activity"></param> public TimestampServiceConnection(TimestampActivity activity) { IsConnected = false; Binder = null; timestampActivity = activity; }