boolean isBound = bindService(new Intent(SocketServiceController.this, SocketService.class), mConnection, Context.BIND_AUTO_CREATE);
servicio de enlace siempre devuelve falsa para mí ... ¿Podría alguien decirme los posibles errores que pude haber hecho ...Android servicio de enlace devuelve falso cada vez que
código de servicio es el siguiente
public class SocketService extends Service{
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return myBinder;
}
private final IBinder myBinder = new LocalBinder();
public class LocalBinder extends Binder {
public SocketService getService() {
return SocketService.this;
}
}
@Override
public void onCreate() {
super.onCreate();
}
public void IsBoundable(){
Toast.makeText(this,"Is bound", Toast.LENGTH_LONG).show();
}
public void onStart(Intent intent, int startId){
super.onStart(intent, startId);
Toast.makeText(this,"Service created ...", Toast.LENGTH_LONG).show();
}
@Override
public void onDestroy() {
super.onDestroy();
}
}
códigocontrolador de servicio es el siguiente:
public class SocketServiceController extends Activity{
private SocketService mBoundService;
private Boolean mIsBound;
public SocketServiceController ssc;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ssc = this;
setContentView(R.layout.telnet);
Button startButton = (Button)findViewById(R.id.button1);
Button endButton = (Button)findViewById(R.id.button2);
Button bindButton = (Button)findViewById(R.id.button3);
startButton.setOnClickListener(startListener);
endButton.setOnClickListener(stopListener);
//bindButton.setOnClickListener(this);
TextView textView = (TextView)findViewById(R.id.textView1);
}
private ServiceConnection mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className, IBinder service) {
mBoundService = ((SocketService.LocalBinder)service).getService();
}
@Override
public void onServiceDisconnected(ComponentName className) {
mBoundService = null;
}
};
private void doBindService() {
boolean isBound = bindService(new Intent(SocketServiceController.this, SocketService.class), mConnection, Context.BIND_AUTO_CREATE);
mIsBound = true;
//mBoundService.IsBoundable();
}
private void doUnbindService() {
if (mIsBound) {
// Detach our existing connection.
unbindService(mConnection);
mIsBound = false;
}
}
private OnClickListener startListener = new OnClickListener() {
public void onClick(View v){
startService(new Intent(SocketServiceController.this,SocketService.class));
doBindService();
}
};
private OnClickListener stopListener = new OnClickListener() {
public void onClick(View v){
stopService(new Intent(SocketServiceController.this,SocketService.class));
}
};
@Override
protected void onDestroy() {
super.onDestroy();
doUnbindService();
}
}
Oye ... todavía me estoy poniendo falso .... lo estoy haciendo en el simulador ... ¿y debería agregar algo extra en el archivo de manifiesto que no sea ...? –
han estado tomando bastante tiempo para resolver este problema ... ¿hay algo más erróneo en este código? –
Entendido: getApplicationContext(). BindService tuvo que usar esto ya que tabspec no se puede vincular a la actividad ... estaba llamando dentro de una pestaña ... –