android Service

Common bugs/problems with the Android SDK the Emulator and the ADT-Plugin.

android Service

Postby ivo_k » Tue Mar 01, 2011 9:38 pm

Hello everybody! I'm just new to this forum.

I read the book "Professional Android 2" from Reto Meier, and I'm stuck at page 298: Binding an Activity to a Service.
Now, with help of debugging, I think I know what problem I have, but not really how to solve it.

(In the Service, I return Service.START_STICKY; in onStartCommand( .... ) )

The Service is in MazeAlgService extends Service.....

The Activity class: MazeAlgorithm extends Activity creates the Service at


public class MazeAlgorithm extends Activity{

protected void onCrate(Bundle saveInstanceState){
Intent bind Intent = new Intent(MazeAlgorithm.this, MazeAlgService.class);
bindService(bindIntent, mConnection, Context.BIND_AUTO_CREATE);
}


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;
}
};

//BELOW, WE HAVE AN INNER (HELPER) CLASS:

public class MazeReceiver extends BroadcastReceiver{

@Override
public void onReceive(Context context, Intent intent) {


int dotask = getIntent().getIntExtra(MazeAlgService.LABYRINTH_MAZE, MazeAlgService.SERVICE_MAZE);
Log.d(TAG, "dotask = " + dotask);

// mazepath is an int[][] array
mazepath = serviceBinder.getMazePath().clone();
serviceBinder.stopService();
printMaze(dotask);
}
} // RIGHT HERE SEEMS TO BE THE PROBLEM!!!!! , the end of the inner class
} // end of class MazeAlgorithm

When the program reaches the end of the INNER class, it seems not knowing where to return to. I get the white tab screen with the message Source not found. Then the button below "Edit Source Lookup Path..."
And in the console window, logcat: request time failed: java.net.SocketException: Address family not supported by protocol.

At this stage I know that the Service works. But the inner class seems to be the problem at the end.

Hopfully someone has a hint to a solution.
/Ivo
ivo_k
Freshman
Freshman
 
Posts: 4
Joined: Tue Mar 01, 2011 8:45 pm

Top

Re: android Service

Postby blundell » Thu Mar 24, 2011 10:38 am

Code: Select all
protected void onCrate(Bundle saveInstanceState){


Should be :

Code: Select all
public void onCreate(Bundle saveInstanceState){


:-)
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Top

Return to SDK/ADT/Emulator Problems

Who is online

Users browsing this forum: Google [Bot] and 1 guest