Hi! I'm reading the book Professional Android 2 Application Development from Reto Meier. I'm stuck on page 298.
I need having a Service in the app, and almost it works, but not quite. I get my Service to run, but cannot bind to it (so my reference serviceBinder is never initialized; e.g. I get the NullPointerException. The following code snippet is never run, and I am confused where to put it: Please note that I return Service.START_STICKY; from onStartCommand( ...) from the Service. Following makes the service to run: @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); // Bind to the service Intent bindIntent = new Intent(MazeAlgorithm.this, MazeAlgService.class); bindService(bindIntent, mConnection, Context.BIND_AUTO_CREATE); } but this code below is NEVER run (so serviceBinder is never initialized): private ServiceConnection mConnection = new ServiceConnection(){ public void onServiceConnected(ComponentName className, IBinder service){ // Called when the connection is made. serviceBinder = ((MazeAlgService.MyBinder) service).getService(); } public void onServiceDisconnected(ComponentName className){ // Received when the service unexpectedly disconnects. Context context = getApplicationContext(); serviceBinder = null; } }; MazeAlgService is the service, called from the class MazeAlgorithm. Where to shall I put the code above in the context of the Activity? Nicest thanks to all of you (and just for info: I'm new to this group... :-) ) /Ivo -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en