Ok, I'm new to Android development and trying to bind to a service so that I can call methods on the service after it starts. The actions and services described below are part of the same application, so there should not be any problems, but every time I run my application, I get the following error:
java.lang.ClassCastException: android.os.BinderProxy
The line in which this occurs is as follows:
LocalBinder binder = (LocalBinder) service;
My opcode (simplified):
public class Main extends Activity { boolean gpsBound = false; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } @Override protected void onStart() { super.onStart();
Services:
public class GPSService extends Service { @Override public void onCreate() { super.onCreate(); } @Override public IBinder onBind(Intent i) {
And finally, my LocalBinder:
public class LocalBinder<S> extends Binder { private String TAG = "LocalGPSBinder"; private WeakReference<S> mService; public LocalBinder(S service){ mService = new WeakReference<S>(service); } public S getService() { return mService.get(); } }
I understand the meaning of the ClassCast exception, but I canβt figure out what to do! I followed this example in the google documentation, but it still doesn't work. Can anyone shed light on what might be causing this?
Thanks in advance!
source share