title: android bind service to activity
body: <p>I have seen several similar examples here but can't seem to get my service to bind with activity.</p>
  
  <p>I am getting the error </p>
  
  <blockquote>
    <p>"android.os.binderproxy cannot be cast to IC_CommissaryService".</p>
  </blockquote>
  
  <p>My service looks like this:</p>
  
  <pre><code>public class IC_CommissaryService extends Service 
  {
      @Override
      public IBinder onBind(Intent intent) 
      {
          return mBinder;
      }
  
      private final IBinder mBinder = new LocalBinder();          
  
      public class LocalBinder extends Binder 
      {       
          IC_CommissaryService getService() 
          {
              return IC_CommissaryService.this;
          }
      }
  
      public int onStartCommand(Intent intent, int flags, int startId)
      {
      }
  
      private boolean SendOrderToServer(int orderID)
      {
          /* do stuff*/
      }
  </code></pre>
  
  <p>}</p>
  
  <p>and my activity looks like this:</p>
  
  <pre><code>public class SubmitOrders extends Activity 
  {
      IC_CommissaryService ICservice;
  
      @Override
      public void onCreate(Bundle savedInstanceState) 
      {
          Intent serviceintent = new Intent(this, IC_CommissaryService.class);
          serviceintent.putExtra("binded", true);
          bindService(serviceintent, mConnection, Context.BIND_AUTO_CREATE);
      }
  
      private ServiceConnection mConnection = new ServiceConnection() 
      {
          @Override
          public void onServiceConnected(ComponentName className, IBinder service) 
          {
              Log.e("TEST", "SERVICE CONNECTED");
              try
              {
                  ICservice =(IC_CommissaryService.LocalBinder)service).getService();
                  for(int i = 0; i &lt; Submitorders.size(); i++)
                  {
                      ICservice.SendOrderToServer(Submitorders.get(i).intValue());                                                
                  }
              }
              catch(Exception ex)
              {
                  Log.e("Error", "Error connecting service: " + ex.getMessage());
              } 
          }
  
          @Override
          public void onServiceDisconnected(ComponentName className) 
          {           
          }
      };
  }
  </code></pre>
  
  <p>I am getting the error in my activity on the line <code>ICservice =(IC_CommissaryService.LocalBinder)service).getService();</code></p>
  
  <p>I think I have done the same as people already suggested in other posts so any help please?</p>
  
  <p>thanks</p>