How to debug android apps running in background and Foreground - android

When we remove an app from foreground logcat gets full of other stuff.

If you have an app running on your device and you want to attach a debugger to its process then you can hit the "Attach Debugger" button as shown in the image below:
Then select the process you want to debug. You can only do this with your own apps of course.

Related

App is running on Android Monitor but not on android

As I wanted to debug my app, I clicked the Debug button. After this, if I was trying to run the app manually, a message appeared saying "Waiting for debugger to attach...". I turned off and turned on the "Debuggable app" option in the Developer settings and rebooted my phone and this dialog disappeared.
But now when I'm trying to click the Run button in Android Studio, the app doesn't run, but lines of log are running at the ADB window (Android monitor). Feels like it's running in the background.
The only way to launch my app and track it is to click the Debug button, set the Breakpoint, run the app manually, click the Debug button again. But I don't want to Debug!
P.S. Sorry for that bad English.
Stop the debugging process and rebuild your project. It works for me. Try it.

How to Attach debbuger to process from the first line without compile code every time

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

AS3 is there an event for when Android app is exiting on it's own?

Ok, I made an app for Android. And when we push the middle button or back(lefthandside) button of Android phone, we all know that Android apps still runs in the background.
So my code is this:
the first line(addEventListener) is in a private function which runs as soon as you open the app.
NativeApplication.nativeApplication.addEventListener(flash.events.Event.EXITING, onMyAppExit)
private function onMyAppExit(event:flash.events.Event):void{
trace("onMyAppExit is running");
saveProgress();
}
Basically, I want saveProgress() to run when the app ACTUALLY exits from running in the background. I noticed that my app actually exits when I open another app like Candy Crush. I guess the Android OS exits apps automatically when the apps are not being used and when the app you are using takes a lot of RAM. However, my code only works when I run my app in AIR Debug Launcher(Mobile). I know that because I see the trace in the function in my output window when I click on the x button on the right corner of the app window. But when I connect my Android phone to the computer and then ---> AIR3.8 for Android settings ---> Publish, and then I "Begin Remote Debug Session", and I open my app first, then open Candy Crush so that the Android OS automatically exits my app, I don't see the trace. So I finalized that the code didn't work on my phone.
I think you should use the event Event.DEACTIVATE,
when the app go to background you can save all so the os can kick your app off it's still safe :)
With that you have the event Event.ACTIVATE when the app go back on the foreground so you can handle it to revive your level.

Android: how to debug app's start-up process

I am investigating some issues which happen during my app's startup process, but DDMS won't start the debug mode until the process has started, is there a way I can capture the events earlier?
I know that this is a couple of years late, but for any future searches:
Putting WaitForDebugger into your code is one way.
Unlocking developer options (by tapping on the build number in system information on the android device) in Settings allows us to select an application for debugging and then opt to wait for a debugger whenever the program is launched. This allows us do the equivalent of adding and removing WaitForDebugger without modifying and reinstalling the code each time.
For Android Studio, here is what worked for me:
Add
android.os.Debug.waitForDebugger();
Where you want to start debugging.
Then add a breakpoint just after it in your code
Compile your app and pass it to your device
Restart your device
Once it's up, attach the debugger:
Start debugging
You should implement your own Application class which extends
Application and override the methods onCreate and so.. . This class will be your starting point of your app.
also set it as your application in the manifest.
Android can wait for the debugger to attach to your application before the app gets launched. This is a developer option called Wait for debugger.
Steps
Enable developer options (tap build version 7 times)
Enable USB debugging
Install your application onto your device using debug mode
In developer options: Press Select debug app and select the app
Enable Wait for debugger, as shown in screenshot:
Launch your app:
e.g. If testing app launch from terminated state from a push notification, send that push notification to the device.
e.g. If testing app launch from Google Assistant, use the Google Assistant to trigger this.
The app would not launch yet, instead a dialog would show up:
Attach the debugger, by pressing the Attach Debugger to Android Process button
My situation
For anyone interested/ for my future reference: I wanted to debug my Android application receiving a push notification message when the app was in the terminated state. It was actually a Flutter app running on Android, so this is relevant for both Android and Flutter.
I have revoked the API key revealed in this GIF.
Tip
If Wait for debugger is enabled, sometimes you need to detach or close Android Studio's debugger and re-attach it if you want to handle a subsequent application launch successfully. Otherwise, the app would never launch.
Notice, I send a push notification from a device (left device, iOS), and the push notification causes the app to launch on the (right device, Android). Then I attach the debugger, and the program pauses at the breakpoint I set inside FirebaseMessagingReceiver.
I wrote another version of these steps here.

Why has the Eclipse Debugger/Emulator disconnected from my app?

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.

Categories

Resources