最終更新:2016-07-06 (水) 17:59:59 (2843d)  

Context.bindService
Top / Context.bindService

abstract boolean bindService(Intent service, ServiceConnection conn, int flags)

メモ

引数

android.content.Intent

android.content.ServiceConnection

  • サービスに接続したときとサービスから切断したときに呼び出されるコールバックメソッドを持つクラスのインスタンス
  • onServiceConnected
  • onServiceDisconnected?
      MyIntentService myService;
      ServiceConnection serviceConnection = new ServiceConnection(){
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
          Log.d(TAG, "onServiceConnected");
          myService = ((MyIntentService.MyBinder)service).getService();
        }
    
        @Override
        public void onServiceDisconnected(ComponentName name) {
          Log.d(TAG, "onServiceDisconnected");
          myService = null;
        }
      };

flags

  • Context.BIND_AUTO_CREATE - automatically create the service as long as the binding exists.
  • Context.BIND_DEBUG_UNBIND? - include debugging help for mismatched calls to unbind.
  • Context.BIND_NOT_FOREGROUND? - don't allow this binding to raise the target service's process to the foreground scheduling priority.
  • Context.BIND_ABOVE_CLIENT? - indicates that the client application binding to this service considers the service to be more important than the app itself.
  • Context.BIND_ALLOW_OOM_MANAGEMENT? - allow the process hosting the bound service to go through its normal memory management.
  • Context.BIND_WAIVE_PRIORITY? - don't impact the scheduling or memory management priority of the target service's hosting process.

呼び出されるメソッド

ライフサイクル

関連