How to react on a force close? - android

I'm developing a first app for android, and I sometimes get a message "this application stopped unexpectedly" and a "close" button.
How can I find out what's wrong? When the phone is connected to the computer, it would show in the Logcat of Eclipse, but my phone is not always connected to my computer. How do you handle that? How do you handle the error reporting in your app when it's not in debuggable status?
How can I configure my app to restart in such an occasion? I have an other app (not developped by me) which sometimes shows the message that it restarted after memory low (or something like that). I'd like to restart my app too when, for whatever reason, it crashed.
Anybody?

I am not sure about the second question but for the first part you can run adb logcat in background. for that just go to the folder location where adb.exe esixts, in command prompt and just type
adb logcat > /data/log.txt &
it will run in the background and store the logs in log.txt file. When you are done with your force close. just type following command
adb pull /data/log.txt .
it will extract the logs, and will put in the current directory location, you can open it using any text editor.

If your device is not connected to a computer, you can see the logcat output using the following app: aLogcat
Also, I'm not sure that restarting an app that has just crashed is a good idea. This could lead to an infinite loop of crashing/restarting.

Related

What is happening when logcat prints the logs between the time a device was last connected to Android Studio and the present?

Sometimes when a phone connects to Android Studio, it will print logs between the time it was last connected to Android Studio and the present. This is cool, but I can not replicate it. Some times it happens, sometimes it does not.
I have a guess that this is a feature of USB and wireless debugging, and that logs are put in a temporary file so they can be sent to logcat when reconnected. If so, how do I keep the USB debugging from turning off when testing my device in the field during the day, so I can get the logs that were printed during the day? If not, what is happening?
The logs are nothing to do with Android Studio (or logcat in general) - it's just system logging happening on the device, and that happens whether it's connected to a log-reader or not.
At a guess, what's happening is your app's process is being closed, so the next time it runs it gets a different PID (process ID). When you connect it to the computer, your dropdown shows the currently running app process, and filters by its PID, so you don't see the old stuff.
You've probably seen this while debugging - if you re-run your app, the log "clears" and gives you a fresh one for the new run of the app. The old log messages are still there (as well as a hell of a lot of other logs for all the stuff going on on the device - it is noisy), it's just that you can't see them.
The simple thing to try is going to the filter dropdown on the right of the logcat window, and choose No filtering. Then in the filter query thing next to it (with the 🔎) type the name of your app, maybe its package. It's not perfect but it should show you all of the logs it has from your app, along with a bunch of system stuff that's also referring to it. You could get clever with PIDs or setting up a custom filter in the dropdown to get better results.
You might also be interested in the guide (with some filtering tips) and the commandline version if that's more useful to you

LogCat is not showing null pointer exception

My LogCat is often not showing null pointer exceptions..
Sample:
ProgressDialog pd;
ps.show();
Application stops (do not reacts for any action), but there is no information about any reason in logcat.
Another sample is with database - if there is no DB and I'm making actions on it, the same happens.
I tried (that action with DB) on my colleague's phone and there was normal error. I have all needed programmer options in my phone turned on.
Maybe someone know , why it is so? It was not burdensome, when I had small app, but now when it's bigger, it can be really frustrating.
I get this with android studio too...
Close android studio, restart ADB, and generally it starts working for me.
If that does not work then put a breakpoint at the line .show(); ... Then open up the logcat and then skip over the breakpoint. It then shows, I have similar issues.
(Windows 7 64 bit - Android Studio 0.82)
I dont like the IDE logcat option honestly.
The SDK comes with an adb binary, use the logcat option from there via
adb logcat or my personal favorite built in alias, adb lolcat
This will give you the log information for EVERYTHING happening on the device, and can be useful tracking down issues caused by device state.
For example, you can see network changes in the logcat, and if your app crashes on network call you wouldnt have any idea why if you just used the logcat output from your app.
In my case I was using: Thread.setDefaultUncaughtExceptionHandler in my application file. If that is not turned off during debugging you won't see any exception output. ( Just make sure to turn it back on again when you release so you can still handle your issues ).

Application throws an error after relaunch

My application throws an error when I attempt to start it from "Recent applications". Problems :
Error appears only if application was inactive (stopped) for a long time (approximately one hour). I can't catch this error by myself - when I'm killing process by myself and then relaunched it there is no errors!
I can't see Exception log in debugger, since it's disconnects after so long time.
How can I catch such kind of errors in debugger? Looks error appears only when OS kills application by itself.
EDIT
I didn't overrided onResume method. Just onStart, and there is nothing special except instantination of my SQLiteOpenHelper.
even if your app is in paused/stopped state, log cat will still be working as long as device is connected. make sure you selected all logs options in windows > devices > all logs instead of windows > devices > com.your.project .
so when you will try to relaunch crash must be recorded in logCat
if still have any issue, install logcat app from market and refer it for logs.
Sounds like there might be an issue in your
OnResume
call. What is your application doing? Is it using a location manager? Does it have services or threads that need to be restarted? More infomation please.
Look through the Android application lifecycle chart:
http://developer.android.com/reference/android/app/Activity.html
It should help you understand what's going on. If all else fails, add a lot of logging to logcat and see what the output looks like on your end. As long as you don't unplug the device, you shouldn't lose that in Eclipse. If you do, you can always run "adb logcat" from the command line or shell to see exactly what's happening.

DDMS Not showing my logs

I'm having an issue with DDMS.
System logs are appearing fine, but my own logs aren't showing up.
I'm trying to view the logs in ddms.exe.
I've tried restarting adb, stop/start adb, restart ddms, restart emulator, recreate avd.
Nothing has had an effect. I've tested this with two different apps.
Any ideas?
EDIT same issue in logcat.
No filters selected
I've restarted the computer
As i remember you have to make you app debuggable ("android:debuggable=true") in your manifest file. Or you can find your app in DDMS but can't get access for your own logs?
can you try the command:
> adb logcat -s "TAG"
on a terminal/cmd line ?
here "TAG" is the name of the tag which you are giving in your Log
I failed to mention that i'm using a tool called Kony. It is a "write once deploy everywhere" mobile development environment.
When the app is being compiled in release mode (which I was unaware of) all print statements are removed.
Had this not been the case, some or all of the previous suggestions would have worked, i'm sure.
Adding to above.
It is true that the value we are trying to print will not be logged to the console but it is not strictly removal of print statements. Kony.print get executed .
This observation can be checked by building in release mode and trying to print and undefined value, you will get type error thrown.

When did Application restart?

Sometimes I see my app in DDMS restart.As I see it's process id changed.(I'm not sure that,because I don't write log for application oncreate.)
That behaviour ofen happened when I mount SDCard to share USB mode.I'd like to see what happend after mount in my application.So I debug my App,but unfortunately.When mount to share USB mode,application's process id changed and debug been auto stopped.
Why?What happened?What's the strategy for android handle application restart?
And there is another question.Why does sometimes an activity occur an error,thrown an exception dialog,and restart it.Sometimes the android platform just kill the activity and exit.
Maybe it's not a very useful question for develop.But I'm really missing,I want to know the answer.Please help me,friends.Thank you very much.
I used to get into similar cases like yours, what I did to handle and detect is like:
1. Check Device: sometimes devices mal-functioning really cause problems, a bad USB cable will really do restart Android/application.
2. Collect Log: after application restarts, just collect the log from system/event/radio/dumpstate... remember the time when app started to restart then check in log files to look for the causes.
Well, that's my experiences and it works, not in all situations but most of the time.

Categories

Resources