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 ?
Related
I have an Android app that needs to perform a certain task one time after it's installed, and then never again. It uses SharedPreferences to record that it's performed the task successfully.
In order to test this behavior, I run the task via Android Studio on a real device, connected over USB. The problem is, every time I run the app via Android Studio, it reinstalls. As such, it seems to lose its persistent memory (SharedPreferences).
It makes sense that the app's SharedPreferences should be wiped when it's reinstalled. But how do you run an app in the Android Studio debugger without reinstalling it and wiping the persistent memory? I looked at the Android docs for running an app from Android Studio, and from the command line, but none of them seemed to offer a way to run it with a debugger connected without reinstalling.
One option I see to accomplish this would be by closing and re-launching the app from the device itself, and then attaching the debugger in Android Studio to the app's process. But this would mean the debugger misses the first few seconds or so of the process's activity. My app's task gets done in the first microseconds. I should still be able to view the logs from those first few seconds, but not to have full debugger control.
Any ideas?
if you directly run app from android studio from same machine it will not reinstall it updates the app so your sharedpreference will not wiped it remain same. For more info about sharedpreferances http://developer.android.com/reference/android/content/SharedPreferences.html
for debug from first step you can use debug option which run app directly in debug mode (shift+f9)
https://developer.android.com/tools/debugging/debugging-studio.html
I'm trying save compiling time only for debug first app lines code.
There is solution to exit by backPress() and the process still running (and then i can attach debugger to process), but my debug scenario need to check app from start so i need to kill process before debug, which prevent me to attach debugger unless otherwise i'm compiling the app in debug mode.
Does any one know how to prevent compile in debug only for that?
go to settings -> Developer options -> Select app to be debugged -> choose your app
turn on 'Wait for debugger'
then when you launch the app you see this screen:
Now app wait for you to attach debugger and auto start when it's attached
It is actually start the app-process without start launcher activity
I am using Eclipse. I have a breakpoint on onCreate that I want to catch in debug mode when my application is restarted by android because of multitasking. I can connect the Eclipse debugger to my restarted app on the DDMS perspective, but I am never fast enough to catch the breakpoint in onCreate. How to automatically connect the Eclipse debugger when the android app is restarted on the device?
Run the app in debug mode. Right click on project there will a option Debug as below Run as.
Run the app in debug mode. But don't forget to add break point first before running app in debug mode
is restarted by android because of multitasking
Not sure what you really mean by this, but if this imprecise description refers to asynchronous operations (i.e. using AsyncTask) then you may want to add this line before your breakpoint set in code that is run on other than main task:
Debug.waitForDebugger();
Please note that to make it work you need to launch your app in debugging mode (F11)
My app is no longer starting up automatically when I F11 it in Eclipse; the Emulator starts up, but I then have to go and find my app among the applications list/array to invoke it.
Then, when I get to the place in my app where I've set a breakpoint, instead of hitting the breakpoint (Eclipse is not even going into Debug Perspective), my app suddenly "expires" and the Emulator pops up the dialog:
~~~~~~~~~~~~~~~~~~~~~~~~~
Sorry!
The application FifeOrTheDinosaur (process.com.aXX3AndSpace.FifeOrTheDinosaur_Package) has stopped unexpectedly. Please try again.
Force close
~~~~~~~~~~~~~~~~~~~~~~~~~
But then when I click "Force Close," that dialog goes away, and my app starts up again, from its opening Activity...?!?
It's almost as if my app is not the one being debugged by Eclipse -- Eclipse has lost its connection to it or...???
And every time it crashed, I hit the "Force Close" button, whereupon my app starts up all over again. What could have disconnected my app from the Debugging system, so that it:
1) Doesn't run automatically when I run it; rather, I have to "force" it to start up, and when it enters a breakpoint, Eclipse's Debug Perspective is not invoked
2) Continually starts up my app after it has failed...???
I put a breakpoint on a button click handler prior to that one that is working fine, and it does not drop me into the Eclipse debugger, either...???
Update:
The console says:
1) ] Failed to install .apk on device 'emulator-5554': timeout
2) Launch canceled!
Updated 3/30/2012:
If I run the app from Eclipse and immediately shut it down just as the Emulator is starting to initialize, it flashes up three "command window"-type screens, one right after the other, too fast to read what text they contain. Normally the Emulator window simply goes away, so I don't know if this is a clue for anybody as to what might be happening...
That sounds like the normal behavior of android Apps. If one activity crashes you can still go back to the activity the App started with. And if the breakpoints aren't hit then the error might occure before the code line you want to stop at.
Maybe you could set a breakpoint before you change the activity and then debug from there on.
You could also provide your Log output. Errors like that can always happen if you forgot to declare permissions or activities in your Android Manifest.
Everytime I start the emulator from eclipse, I get the following error in my console.
[2010-09-13 17:04:51 - DeviceMonitor]Sending jdwp tracking request failed!
[2010-09-13 17:18:49 - DeviceMonitor]Sending jdwp tracking request failed!
The application works fine, but I am concerned as to why I see this error. Please help
I believe this is coming from the Usage Stats option. I just installed ADT, did a test run and got this error, as well. I went to Window >> Preferences >> Android >> Usage Stats then checked it on. Tried another test and voila! No error!
Kind of annoying, I can imagine...
This is caused after the emulator is closed while eclipse is still running.
When you first run the emulator after starting eclipse, a connection is established between it and eclipse. This connection is used to send messages back and forth between the two programs, and so eclipse can track the progress of the emulator.
When the emulator is closed, the connection is lost, and any attempt by eclipse to send a message results in the error messages you describe.
As Koby said this message comes if you close the emulator after running an application. First of all between successive application running on emulator you don't need to close the emulator. First before running the application you start the emulator by clicking window-->Android SDK and AVD Manager and click on the emulator you want to launch and click on 'start' button and then click on 'Launch' to launch the emulator. After the emulator launches unlock the emulator and keep that emulator minimized. And if you want to run an application go for 'run as android app' and you can see that on the emulator when maximized. After running that application if you want to make some changes in the application you don't need to close the emulator. you press the home button after running the application and keep the emulator minimized. Make the changes on the code and again go for running the application. Thus you can avoid that error message and save time for launching the emulator. if you got that error message then also the application will work properly but you cannot see the messages like uploading app-->installing .apk-->and the success messages. But these will be happening on the background. One way to overcome this is to restart the eclipse.