user1106888
user1106888

Reputation: 255

Starting an app in debug mode from another app

I am launching App B from App A with intent. I want to see debug mode logs in App B. If I launch App B directly I can do it. But if I have to launch it from App A, I cannot use debug. Is there a workaround for this.

Upvotes: 0

Views: 688

Answers (2)

Nanki
Nanki

Reputation: 828

There are two ways to do this. The official way is to set your breakpoint and then use this in your onCreate method:

            Debug.waitForDebugger();

This pauses the app until a debugger is attached, at which point it will hit your breakpoint.

Alternatively you can put a sleep timer in your onCreate method, (e.g. TimeUnit.SECONDS.sleep(30)), which pauses your app long enough for you to attach a debugger.

Upvotes: 0

Julio Lemus
Julio Lemus

Reputation: 661

To see logs: Make sure you have Logcat opened and go to combo to switch between your debug apps are running currently to see each app's logs.

enter image description here

To enable debug mode: You need to have both projects opened together and once you have launched App-B from App-A as you are doing, when App-B will be opened, you can attach debug mode from "Attach Debugger to Android Process" button on its own "Android Project B":

enter image description here

Tested on Android Studio 3.4

If it is not this, maybe we need more details...

Upvotes: 1

Related Questions