I am quite new to Android and have a debugging issue. I know what an ANR is for, and do not see them when I run my app normally. However, when I try to debug my BoradcastReceiver, I am too slow and get the ANR message.
Is there a way to switch off ANR during debug sessions? I could use log statement to see what's happening, but this is annoying....
edit: actually, I don't want to supress the ANRs in the LogCat, I want to tell android not to throw ANRs during debugging. I mean to allow Broadcast receivers to take longer than 5 seconds to run. But I guess it will not be possible and instead I should delegate to a service, which is allowed to run longer, which I also can debug easier.
Thanks in advance!
greets
Go to Settings -> Developer options and check Show all ANRs.
This will show an App Not Responding dialog for apps running in the background. You can click the Wait button in the dialog to prevent the system from killing your process. Note that the dialog is opened automatically for apps running in the foreground. For background apps, you have to enable this option.
No. This message is handled through the Android OS, not your application, and there is no way to hide it on the Emulator. If you don't want to see it and your BroadcastReceiver receives the call correctly, just doesn't run successful code, you can use a try-catch block, and instead of your application crashing, the catch will be handled, wherein you can make a Toast message or whatever you wish.
You may find this resource useful for your problem. Key points:
Use -w to make process wait until debugger is attached. This one actually helps to stop on breakpoints on onCreate()'s. Debug flag is cleared after you attach debugger. Next time app starts in a regular way.
Use --persistent to wait for debugger every time process starts.
Use adb shell am clear-debug-app your.app.package to undo --persistent
Related
I hired a developer to build an app for me, I noticed this issue and he said he doesn't think (or know how) it could be fixed. The issue is that every time my app is launched and you're logged in, this notification appears and stays there even if you close the app, you cannot swipe to remove it, you can either remove the app or kill it, or reboot the phone. Any idea how to fix it, he's using "Pusher"
Here's the example after launching the app
You have to manage your service so that it can be started and stooped as per your usage.
Please post the code or connect with me # napsterkr#gmail.com for further help.
I am building an Android app with a single Activity. The app is supposed to be closed when I click a button which calls the Activity's finish() method.
However, the app is still on the running-app list. Shouldn't the app be closed?
Thanks
Edit:
I can kill the process completely by running the killProcess(), which can be verified by checking the running processes via adb command adb shell ps. However, what is confusing is that if I push the multi-task button, my app still shows up as "running".
int pid = android.os.Process.myPid();
android.os.Process.killProcess(pid);
Also, I'm still curious why finish() won't close a single Activity app completely. Is there a more graceful way to close the app than calling killProcess()?
That's normal. The Apps in running Apps list are not necessary using CPU, but have a saved state. Android manages this by itself, so don't worry. You shouldn't try to kill it
You can only remove your Activities from the Backstack but all apps are still in this running app list. Honestly I don't know why but there is no process going on so it's OK. This is a constant habit of mine to close all applications manually because I think it drains the power but nowadays I know better
I do a research about Android Activity lifecycle. And I know after an app goes to background, it is likely to be killed by system if apps with higher priority need memory, but save the activity with a bundle. And when users come back, system will restore it, that makes user feel good!
I want to know how to make this circumstance, I want to see my application to be killed before hand, not see it when it is used by users, to evaluate whether it is strong or not. Because it may be crashed when this happens.
Enable "Don't keep activities" in the developer options on your phone. This will force kill your app as soon as you put it in the background.
See this question for more detail about how it works:
Whats the main advantage and disadvantage of "do not keep activities" in android
See here for more info on how to enable it:
http://www.pcadvisor.co.uk/how-to/google-android/3590299/32-useful-things-you-can-do-in-android-developer-options/
You can emulate it by sending your app to background and killing it by adb shell am kill your.package.name.
I'm having the follow question how I'm disable Force Stop button, this is to accomplish one task of my project this is not for virus or malware or malicious things. I have to disable it for my service do not be killed because inside him it checks the time and create a file in a determinate time of system this is because my client wants to block the Android OS when it creates. I've already searched and appears if you start the with startForeground() method the force stop button became disable and another solution but i do not find much material is about create a system service if anyone know i will be happy. And if want make a suggestion for my work and works i will be very grateful. Thanks
You can't. The user is always able to stop a service on the phone, as he should be- its his phone, he can decide he doesn't want your app to run anymore.
The force close button appears because your program has entered a state in which it can no longer be executed sensibly (for instance an uncaught exception). Disabling the display of the close button will not solve your problem, you should debug your code.
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)