I saw several similar examples here, but I can not get my service to contact activity.
I get an error
"android.os.binderproxy cannot be passed to IC_CommissaryService".
My service looks like this:
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) { }
}
and my activity is as follows:
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 < 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) { } }; }
I get an error in my activity in the line ICservice =(IC_CommissaryService.LocalBinder)service).getService();
I think I did the same as the people who have already been suggested in other posts to help you?
thanks
source share