Debugging a service
Solution 1:
Here's what you can do in four steps:
First: In the first interesting method of your service (I used on 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
}
Second: Set break points anywhere after the waitForDebugger
command.
Third: Launch app via debug button in your IDE (Eclipse/Android Studio/...). (You should probably have removed the main launch activity from the manifest by now)
Last: Launch adb and run the command to start a service:
cd $PLATFORM_TOOLS
adb shell
am startservice -n com.google.android.apps.gtalkservice/com.google.android.gtalkservice.service.GTalkService
Solution 2:
just make sure you don't forget this line of code in your code and release your apk. if you try running your app without the debugger the line below will get stuck.
android.os.Debug.waitForDebugger();
also you can use the following to determine if the debugger is connected:
android.os.Debug.isDebuggerConnected(); //Determine if a debugger is currently attached.