Home » Android » How to debug two processes in Android?

How to debug two processes in Android?

Posted by: admin June 15, 2020 Leave a comment

Questions:

In my application an activity starts a service which runs as a separate process, I want to debug the Activity as well as the service but debugger does not stop at the breakpoints in service?

Thanks for help.

How to&Answers:

Just to elaborate on the other answers here, you can temporarily put android.os.Debug.waitForDebugger(); in the code of your secondary process to make this easier.

Then, just attach your debugger to the process via DDMS or IntelliJ (or whatever you’re using).

Answer:

Temporarily make it not be a separate process.

@CommonsWare

Answer:

You need to enable debugging on the separate process.

Open the DDMS perspective (as oposed to Debug or Java). In DDMS->Devices, select your service’s process and then click the debug button (little-green-bug button). A debug icon will appear near your process, then you should be able to use breakpoints in your Service.

Note that you need to wait until the remote process starts before enabling debugging. So you may want to ensure the seperate process starts on boot, or set a breakpoint in your main process immediately after the line that starts the remote service.

Before enabling debugging:

enter image description here

After enabling debugging:

enter image description here

(of course temporarily making the service non-remote works too, but I’ve had an instance where that wasn’t practical)