Hello,
I'm trying to use Android services, because i need to share one object
with serials activities.
I'have created, with reference the Google example:
http://developer.android.com/referen...p/Service.html
My first clases exended of the service classe:
***************************
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;
public class BackgroundService extends Service {
/**
* Class for clients to access. Because we know this service
always
* runs in the same process as its clients, we don't need to deal
with
* IPC.
*/
// This is the object that receives interactions from clients.
See
// RemoteService for a more complete example.
private final IBinder mBinder = new LocalBinder();
public class LocalBinder extends Binder {
public BackgroundService getService() {
return BackgroundService.this;
}
}
@Override
public void onCreate() {
super.onCreate();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i("BackgroudService", "Received start id " + startId + ":
" + intent);
// We want this service to continue running until it is
explicitly
// stopped, so return sticky.
return START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
}
***************************
And my second classe is the activity where i want to start and work
with the service:
***************************
void DemarrerService ()
{
BackgroundService backgroundService;
ServiceConnection mConnection = new ServiceConnection()
{
@Override
public void onServiceConnected(ComponentName name, IBinder
service) {
// TODO Auto-generated method stub
mIsBound = true;
Log.i("BackgroundService","Conected");
mBoundService =
((BackgroundService.LocalBinder)service).getService();
// Toast.makeText(this,
"Connected",Toast.LENGTH_SHORT).show();
}
@Override
public void onServiceDisconnected(ComponentName name) {
// TODO Auto-generated method stub
mIsBound = false;
Log.i("BackgroundService","Disconected");
}};
// Establish a connection with the service. We use an
explicit
// class name because we want a specific service
implementation that
// we know will be running in our own process (and thus
won't be
// supporting component replacement by other
applications).
Intent intent = new Intent(this,BackgroundService.class);
boolean a=bindService(intent, mConnection,
Context.BIND_AUTO_CREATE);
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
}
***************************
But the fontion bindservice return always "false" and i can't
determine what is the problem's cause?
Any somebody could help me?
Think's!
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en