Debugging a service
Case:
You may have written/called a service for your application that may run at the background once it is created. But when you run your application you wont be able to see the services when your activity uses the services as it runs at the background and it is not visible. But once the service is completed, it will automatically get closed. So in this case, it is not possible to debug your service like it is done manually for an activity.
Solution:
Please follow the steps below in order to debug your service,
Step 1: In the first interesting method of your service (Used in create ()):
/* (non-Javadoc)
* @see android.app.Service#onCreate()
*/
@Override
public void onCreate() {
super.onCreate();
//whatever else you have to to here…
android.os.Debug.waitForDebugger(); // this line is key
}
Step 2: Set break points after the waitForDebuggerCommand.
Step 3: Launch app via debug button in Eclipse.
Step 4: Now launch adb and run the command to start a service as follows,
cd $PLATFORM_TOOLS
adb shell
am startservice -n com.google.android.apps.gtalkservice/com.google.android.gtalkservice.service.GTalkService