Debug an app at startup using an intent filter

I usually debug my applications by clicking the little error icon in Eclipse.

But now I have inserted an intent filter in my manifest:

 <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />

      

While the application starts automatically when the USB cable is connected, I can no longer debug it. No more stopping at any breakpoint.

How do I debug an application when launched with intent?

Many thanks!

+3


source to share


3 answers


The solution is similar to this, delay in the app at startup due to the launch of the intent filter Then run in the debug window while the app is visible there, attach the app process and viola, you can debug the app as before



+1


source


I ran into this problem and I solved it with the code below. The code builds on previous answers. (Thanks for the ideas!)

  • Place this code above the breakpoint.
  • Run your application using the debug option, not the release. This step pushes the debug APK to the device.
  • Kill the app.
  • Run the app through your intent. The application will stop at this code and spam your log with "Pending Debugger".
  • From studio click "Attach Debugger to Android Process"
  • If all goes well, the application should stop at a breakpoint.


Wait too long and it will be ANR!

    //TODO: Remove me.  Debug only!
    while (!Debug.isDebuggerConnected()) {
        try {
            Log.d(TAG, "Waiting for debugger");
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

      

+1


source


I have a Nexus 6P and there is a "Wait while debugger" switch in my developer options. This worked for me. You must also select an app as your debug app. Msgstr "Select application to debug". And, of course, you must install the debug version of your application. Just debug run in Eclipse or Android Studio.

enter image description here

0


source







All Articles