I am having trouble debugging some code in my DeviceBootReceiver (handles android.intent.action.BOOT_COMPLETED intent). I want to debug this bit, but how does one keep the debugger alive, when the device reboots? Is there any hack that anyone has come across for this?
What I want to do :
Start debugging app via Android Studio
Power down the device
Power up the device
Still be able to get the debugger attached to my app when it starts to handle android.intent.action.BOOT_COMPLETED intent
Any thoughts?
Open your device "developer options" settings;
Scroll down to "select debug app" and make sure your app is selected there;
Check the option "wait for debugger".
This will make sure that when your app is executed, for example when it receives a BOOT_COMPLETED broadcast, the debugger gets attached first.
Hope it helps.
You can re-broadcast the intent by yourself via adb shell:
$ adb shell am broadcast -a android.intent.action.BOOT_COMPLETED
It takes about 30 seconds AFTER your device becomes available for interactions for android.intent.action.BOOT_COMPLETED to be broadcast. You have enough time to start up your application and enter debug mode manually
You might want to print a timestamp to your logcat when the android.intent.action.BOOT_COMPLETED intent is received so you have a better idea of when all this happens
Related
I have an application running on a real device. I am telling it to wait for the debug hook:
adb shell am set-debug-app -w my.app.name
Then, I click "Attach debugger to Android process" from Android Studio.
Debugging starts successfully and my breakpoint is hit.
However, after around 20 seconds, the application is killed on the device and my debug session is terminated.
Is there a way of keeping the application alive such that I can continue debugging?
Otherwise, if the application can not be kept alive, is there a way to keep stepping through in the debug process even though the application is killed?
Have you tried clicking the "Debug app" button next to the instant run button? It automatically installs a build with the debugger attached.
On a side note, your app seems to be crashing. Have you tried looking in the logcat ?
I need to reset alarms after the phone restarts.
I set up a BroadcastReceiver which starts a Service if the intent equals android.intent.action.BOOT_COMPLETED.
The question is: how can I debug this? I mean, I would like to use the Android Studio debugger to see if the Service started correctly. How can I do that?
While developing I wanted to test the situation where the system kills a service. This is because I'm loosing connection when communicating between the Android Wear and the handheld. And I think that it is related with the system killing some services.
Does anyone have a suggestion on how to approach this?
if you're developing in Android Studio while you are running your application in android wear side try to hit the kill button displayed in the console.
When you hit this button all the threads + services + activities from this app will be destroyed. If your service is of type "STICKY" it will start by itself after you kill your application.
As of 2020 we have to do it manually (since we don't have Android Monitor or DDMS anymore).
This was tested on Linux. You need root permission for the device (how to get root for an AVD).
Getting the PID (first number): adb shell ps | grep -i <package-or-part-of-it>
Killing the process: adb shell kill <your-PID>
cdlc's answer works, but another way is if you're developing in Android Studio you can go to DDMS: Tools->Android->Android Device Monitor and press the stop button there and you will also see a sticky service restart.
If you check the developer options on an Android phone, there will be an option to show the running services. Under that option you can choose to stop any service that is running.
Helo !
I am working right now with an application that uses BOOT_COMPLETED receiver.
So if I want to debug this application with some breakpoints in its class, I have to reboot my phone and connect to it in the proper time, but I am always too late.
Have you got any better solutions how to debug my application exact when it starts its lifetime with device reboot case ?
Thanks !
You can wait for a debugger - Debug.waitForDebugger()
Close your emulator and Run the application directly in Debug and select the option to launch the emulator that you want to run it on.
It's an strange thing, but, what if you put a 20 sec pause or loop before your first break point?
In this case logging is better solution than debuggung. I was able to see logs arising from BOOT_COMPLETE processing even in IDEA logcat window. (I also do not value step by step debugging very much, and prefer TDD approach anyway)
I am trying to launch the Main Activity from a broadcast receiver. Can anyone guide me as to how I can do it? I always get "Process is Bad" message.
Thanks
Restart the emulator or just Kill the process that will solve this situation.
When using a real device, the only I found to fix this was:
Uninstall the app through Settings -> Applications.
Remove the battery from the phone (using the Android "Power off" menu did not work).
Turn device on again.
Install the APK again using adb install .
My app didn't show up in the list of processes running on the device (it's a BroadcastReceiver), so I wasn't able to kill that process.
See my answer here for more detail on what didn't work.