Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A proper way to Debug a Service in Android Studio?

Is there a proper way to debug a service in Android Studio? Or Android Studio could not do this? When I try to debug, it will just disconnects the sockets. ("Disconnected from the Target VM, address:'localhost:8600',transport 'socket')

Hopefully you can assist me here..

What I have done as advice by some links here, I had place the .waitForDebugger but nothing happens. Please help me.. Thank you very much.

   @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent mainService = new Intent(this,MainPowerAndVolumeService.class);

    startService(mainService);
    android.os.Debug.waitForDebugger();

    finish();

}
like image 925
The One Avatar asked Sep 20 '13 01:09

The One


1 Answers

There is a button next to "run in debug" (In version 1.1.0 looks like this: A phone icon with a small bug overlaid) to attach the debugger to a running android process. Here is the official info (for IntelliJ, but it's the same in Android Studio): http://blog.jetbrains.com/idea/2011/05/new-in-105-attach-debugger-to-a-running-android-process/

like image 53
OriolJ Avatar answered Sep 27 '22 20:09

OriolJ