A proper way to Debug a Service in Android Studio?

15,875

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/

Share:
15,875

Related videos on Youtube

The One
Author by

The One

Vision to become an Android Programmer expert.

Updated on September 15, 2022

Comments

  • The One
    The One over 1 year

    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();
    
    }
    
  • The One
    The One over 10 years
    Thank for the information. I'm testing it first for sudden disconnection.
  • Virus721
    Virus721 over 7 years
    That's very nice, but how do you get it to run in the first place ? Using the adb shell to install and start the service manually everytime you change a byte in the code is a pain in the ass.