How to debug a broadcast?

In my application, I realized that the broadcast is being transmitted for the general purpose of Android. Thus, the program did not have an interface or initial activity. To debug the willow selected in dev tools, “wait for the debugger” and it actually works (I can debug the broadcast receiver). My problem is that dalvik kills my thread (and all debugging) after a few seconds, so I can not check or try step-by-step instructions. Does anyone know how to solve this?

+7
source share
3 answers

In the developer’s settings: Select the application for debugging → your application Wait for debugging

+1
source

You need your BroadcastReceiver to have this in the manifest:

 android:process=":remote" 

Put this in your onReceive method:

 android.os.Debug.waitForDebugger(); 

Then run the project. After that, click "Attach the debugger to the Android process" and wait until your process appears (it will have this name: your.package.name:remote ). Select your process, then click OK and start debugging.

enter image description here

0
source

Put your stuff in another thread:

  public void onReceive(final Context context, Intent intent) { new Thread(new Runnable(){ @Override public void run() { Log.i("foo","set me as line breakpoint."); } }).start(); } 
-2
source

All Articles