title: Getting java.lang.ClassCastException: android.os.BinderProxy every time i declare and run two services
body: <p>I am encountering following binder.proxy exception every time i declare and run two services. One service runs in different Process(Private to app)  and another service runs in same process as My Application is running in(Default App Process) with a Binder Implementation. </p>
  
  <p><strong>AndroidManifest.xml:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.service.check"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk
          android:minSdkVersion="8"
          android:targetSdkVersion="21" /&gt;
  
      &lt;application
          android:name="com.service.check.MainApplication"
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name=".MainActivity"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
           &lt;service
              android:name="com.service.check.SecondService"
              android:exported="false"/&gt;
  
          &lt;service
              android:name="com.service.check.FirstService"
              android:process=":newProcess" &gt;
          &lt;/service&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>I am launching my first service in MainActivity on Button click as:</p>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>public class MainActivity extends ActionBarActivity implements OnClickListener {
  
      private Button mLanchServiceBtn;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          mLanchServiceBtn=(Button) findViewById(R.id.launch_btn);
  
          mLanchServiceBtn.setOnClickListener(this);
      }
      @Override
      public void onClick(View v) {
         //Starting first service
          Intent launch=new Intent(this,FirstService.class);
          startService(launch);
  
      }
  }
  </code></pre>
  
  <p>And second service in MainApplication class as.</p>
  
  <p><strong>MainApplication.java</strong></p>
  
  <pre><code>    public class MainApplication extends Application {
  
          private SecondService.LocalBinder mBinder;
          private ServiceConnection mConnection = new ServiceConnection() {
  
              @Override
              public void onServiceConnected(ComponentName className, IBinder service) {
                  mBinder = (LocalBinder) service;
              }
  
              @Override
              public void onServiceDisconnected(ComponentName arg0) {
              }
          };
  
          @Override
          public void onCreate() {
              super.onCreate();
  
              //starting second service               
              Intent launch=new Intent(this,SecondService.class);
              startService(launch);
  
              //Binding to it 
              bindService(launch, mConnection, BIND_AUTO_CREATE);
          }
  
      }
  </code></pre>
  
  <p><strong>FirstService.java</strong></p>
  
  <pre><code>public class FirstService extends Service {
      @Override
      public IBinder onBind(Intent intent) {
          return null;
      }
  }
  </code></pre>
  
  <p><strong>SecondService.java</strong></p>
  
  <pre><code>public class SecondService extends Service{
  
      //Service Containing Local Binder
      private LocalBinder mBinder=new LocalBinder();
      @Override
      public IBinder onBind(Intent intent) {
          return mBinder;
      }
      class LocalBinder extends Binder{
  
          public LocalBinder() {
          }
      }
  }
  </code></pre>
  
  <p><strong>StackTrace:</strong></p>
  
  <pre><code> 02-05 10:32:25.035: E/AndroidRuntime(1424): Process:
  
   com.service.check:newProcess, PID: 1424 02-05 10:32:25.035:
   E/AndroidRuntime(1424): java.lang.ClassCastException:
   android.os.BinderProxy cannot be cast to
   com.service.check.SecondService$LocalBinder 02-05 10:32:25.035:
   E/AndroidRuntime(1424):    at
   com.service.check.MainApplication$1.onServiceConnected(MainApplication.java:23)
   02-05 10:32:25.035: E/AndroidRuntime(1424):    at
   android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1101)
  </code></pre>
  
  <p>I have referred the following links to sort out the issue which says, 
  if my activity and service are in separate processes then we should not bind the way I have done.</p>
  
  <p><a href="https://stackoverflow.com/questions/10573931/android-service-android-os-binderproxy-error">Android service android.os.BinderProxy error</a></p>
  
  <p><a href="https://stackoverflow.com/questions/25049176/java-lang-classcastexception-android-os-binderproxy-cannot-be-cast-to-localbind">java.lang.ClassCastException: android.os.BinderProxy cannot be cast to LocalBinder</a></p>
  
  <p><strong>But in my case:</strong>
  I am binding to <strong>SecondService</strong> from <strong>MainApplication</strong> and both are running in same Process(i.e Default Application Process). Still I am facing binderProxy exception in <strong>SecondService</strong> , And my <strong>FirstService</strong> runs in separate process which I am not even binding to.</p>
  
  <p>Please help me out with this situation and, Suggest me a best possible way so that I can implement same scenario without any crash.</p>