Tech Blog

Android

How to avoid detach of Android Debugger while debugging Android Process?

By Ankur Agrawal2 min read
← Back to blog

OVERVIEW: 

Recently, I came across this problem many times where I attached the debugger to the Android Process, debug breakpoints were hit and I started evaluating some values or doing step over or step into debugging and suddenly, App isn’t responding dialog comes and debugger detaches from the process.

To avoid detaching of the debugger from the Android Process, we can set our app as a debug app from the Developer options or from ADB. 

HOW TO SET OUR APP AS A DEBUG APP?

FROM DEVELOPER OPTIONS : 

  1. Go to Settings, scroll down to Developer options. (If Developer options is not seen, Go to About Phone setting and tap on Build Number 5 times to enable Developer options).
  2. Inside Developer options, enable USB debugging.
  3. Go to Select debug app option and click on it.
  4. Select your application which you want to debug from the application list.

The screenshots below show the above steps.

Kudos! You have selected your app as a debug app.

If you want to clear the debug app, select nothing from the application list.

FROM ADB COMMAND : 

We can also use adb command to select and clear debug app. It’s more quicker and convenient than using Developer options.

adb command to select debug app : 

adb -s <your device name> shell am set-debug-app -w –persistent <your app package name>

can be used if more than one device/emulator are connected.

otherwise, 

adb shell am set-debug-app -w –persistent <your app package name> 

can be used.

Here, 

-w flag is what sets the Wait For Debugger option in Developer options. You can avoid using this flag if you do not want to enable this option.

–persistent flag tells the system to save this, and not treat this as a one-time action.

adb command to clear debug app : 

adb -s <your device name> shell am clear-debug-app

can be used if more than one device/emulator are connected.

otherwise, 

adb shell am clear-debug-app 

can be used.

Thanks for reading, 

Cheers!

Keep reading

You may be interested in

Browse all articles →
Android Download file with Data URL
July 23, 20241 min read

Android Download file with Data URL

What is a Data URL? Data URLs are the type of URL scheme that is used to embed usually small types of files. In this URL, inline files are prefixed with the data: MIME type. data:[<mediatype>][;base64],<data> To download files having Data URLs inside Android: Firstly, we need to get an extension of the file from […]

By Bansari PanditRead More →
Download the file with blob URL in Android WebView
July 23, 20242 min read

Download the file with blob URL in Android WebView

What is the Blob URL? Blob URLs can only be generated by the browser with use of internal mapping and used within the current document while it’s open which means it is valid for the same session (ie. the life of the page/document). The blob URL looks like this: blob:http://example.com/550e8400-e29b-41d4-a716-446655440000 Below is the sample HTML […]

By Bansari PanditRead More →
Key Terminologies in Android Enterprise
December 20, 20227 min read

Key Terminologies in Android Enterprise

Android Enterprise is a Google-led initiative to enable the use of Android devices and applications in a workspace. This program offers APIs and tools for developers to integrate support of Android devices into the EMM (enterprise mobility management) or UEM (Unified Endpoint Management) solutions. The following are the key terms associated with Android Enterprise. This […]

By Sandeep KadamRead More →