(FRONT) FRONT (2025)

Return to key-value service Key Value service

   1:  package com.voipplus.mmsclient.serviceLocalStorage;
   2:  
   3:  import android.content.ComponentName;
   4:  import android.content.Context;
   5:  import android.content.Intent;
   6:  import android.content.ServiceConnection;
   7:  import android.os.IBinder;
   8:  import android.util.Log;
   9:  
  10:  public class KeyValueServiceStarter {
  11:      private static final String TAG = "KeyValueServiceStarter";
  12:      private KeyValueService keyValueService;
  13:      private boolean isBound = false;
  14:      private Context context;
  15:      private KeyValueServiceConnectionListener listener;
  16:  
  17:      public interface KeyValueServiceConnectionListener {
  18:          void onKeyValueServiceConnected(KeyValueService service);
  19:      }
  20:  
  21:      public KeyValueServiceStarter(Context context, KeyValueServiceConnectionListener listener) {
  22:          this.context = context;
  23:          this.listener = listener;
  24:      }
  25:  
  26:      private ServiceConnection connection = new ServiceConnection() {
  27:          @Override
  28:          public void onServiceConnected(ComponentName className, IBinder service) {
  29:              KeyValueService.LocalBinder binder = (KeyValueService.LocalBinder) service;
  30:              keyValueService = binder.getService();
  31:              isBound = true;
  32:              Log.d(TAG, "KeyValueService connected");
  33:              if (listener != null) {
  34:                  listener.onKeyValueServiceConnected(keyValueService);
  35:              }
  36:          }
  37:  
  38:          @Override
  39:          public void onServiceDisconnected(ComponentName arg0) {
  40:              isBound = false;
  41:              Log.d(TAG, "KeyValueService disconnected");
  42:          }
  43:      };
  44:  
  45:      public void bind() {
  46:          Intent intent = new Intent(context, KeyValueService.class);
  47:          context.bindService(intent, connection, Context.BIND_AUTO_CREATE);
  48:      }
  49:  
  50:      public void unbind() {
  51:          if (isBound) {
  52:              context.unbindService(connection);
  53:              isBound = false;
  54:          }
  55:      }
  56:  
  57:      public void startAndBindService() {
  58:          Intent intent = new Intent(context, KeyValueService.class);
  59:          context.startService(intent);
  60:          context.bindService(intent, connection, Context.BIND_AUTO_CREATE);
  61:      }
  62:  }
  63:  

Return to key-value service




AndroidMosaic context:



Comments ( )
<00>  <01>  <02>  <03>  <04>  <05>  <06>  <07>  <08>  <09>  <10>  <11>  <12>  <13>  <14>  <15>  <16>  <17>  <18>  <19>  <20>  <21>  <22>  <23>  <24>  <25
Link to this page: http://www.vb-net.com/AndroidMosaic/KeyValueServiceStarter.htm
<TAGS>  <ARTICLES>  <FRONT>  <CORE>  <MVC>  <ASP>  <NET>  <DATA>  <TASK>  <XML>  <KIOSK>  <NOTES>  <SQL>  <LINUX>  <MONO>  <FREEWARE>  <DOCS> <TRAVELS> <FLOWERS> <RESUME> < THANKS ME>