Detect app crash in android - android

I'm building an app that sometimes crashes, I want to know that it crashed in the next time I opened it so I can suggest to the user some post-crash options.
How can I detect the crash?
Also I want to be able to save the user's work before it crashes, I means real time detection of crash, can I do it without knowing where it crashed?

You will need to know where it crashed in order to set the try/catch blocks in the right place to, er, catch the crash and save the data or whatever you have in mind.
This is known as "graceful" termination if you want to consider it in more detail.
Unfortunately neither Java destructor/finalize methods nor lifecycle methods such as onDestroy are anywhere near as robust as try/catch blocks so I'm afraid that is your only option, and how many of us deal with exception prevention. No-one would wittingly provide a user experience that crashes, much less with loss of their data.

Take a took at the ACRA library. You can configure it so whenever a crash happens you can control it and even send the crash log by email

You can use try/catch blocks, then send details on the Exception in your catch.

There are implement UncaughtExceptionHandler as mentioned in these answers and write crash report in some file or use it another way.

ACRA is already mentioned.
However for paid version, I found BugSnag is very good at this.
Or if you want to take the extra mile, try AppSee.
AppSee even has video recording session of how the crash happens. It is from tapping that button on the second list, the menu button or even when the user slides left in your viewpager.

Related

how to see FatalExceptions in logcat when using Kotlin

I've just started work with Koltin and my question might be a little strange to someone who have more experience,
but how can i see fatalExceptions in logcat? For example, i have an app that is already developed by another dev,
there is an error in one activity - after pressing the button apps crash and restart to main activity.
I don't see any usefull informations in logcat(in fabric also!), moving on trough whole code from listener to fragment and many classess is very time consuming. There must be some way to figure it out quicker, right?
Exceptions should be shown/thrown in logcat, same as with Java.
If the exception is thown within rxjava or a kotlin coroutine, make sure you have defined an error handler, otherwise the exception might get swallowed.
Then make sure you have selected the right app in logcat and that no filter is active.
Also make sure there is no other global Exception handler defined besides fabric.

how to get the event of app instance clearing in android

in my app I am using push notifications to notify the user about something.Based on different app state I have to assign different activities to click event of notification. If the user press home button and app is in background i have to handle that scenario as well. But here the issue come when user clear the app instance from memory. If user do that I have to consider it as app closed. But i dont know how to get that app instance clear event. Please help me.
The task you are willing to solve is equivalent to protection against the task manager. I am not sure that your app knows better than the user whether or not to show the ads. Please do not create malware.
Try the UncaughtExceptionHandler stuff like setUncaughtExceptionHandler(). I am not sure it will be necessarily called, and it may depend on the Android version, but it is something to start with.
Another possibility is to use one or more remote service(s). The processes will not die all at once, there's a good chance that one process may notice the death of another process. There should be some kind of wait-for-process-to-complete at least on the JNI level.
One more possibility is to use two applications, one monitoring the other...
After you solve this problem, please post your own answer telling the world what you did.

How to monitor all running apps activities lifecycles and crashes?

I'm trying to create a monitor service which would know when apps start/resume/restart/pause/... and also when apps crashes.
I have tried to read logcat, but it seems that calls to [onCreate()/onStart()/onRestart()/...] are not logged into logcat.
Is there a way to catch all these method calls for all running apps ? Is there a way to know when an app crash ?
Note: The service don't need to be notified as soon as these events happens, few seconds/minutes after is also okay.
Refer to my code in this answer:
Android how to know an app has been started and range apps priority according the starting times
You can monitor it as follows:
If an app is in the foreground, that is if it is in start, then it will be the first item of the List taskInfo.
If it is paused, it will no longer be the first item in that list.
To check resume, see if it previously was not the first item, but , in the current iteration, it is the first item.
I am not too sure about the crash part, but maybe you can find a similar way from the above logic.
You can check out Crashlytics for crash tracking. You can see crashed lines in methods as well.

Android Force Close Uncatchable Unreportable

I've released my second game project on the Android Market this week, and immediately had multiple 1-star reports due to force closes. I tested it on many handsets and many emulators with zero issues. I'm completely at a loss for how to proceed and looking for advice.
I use Thread.setDefaultUncaughtExceptionHandler to intercept and report uncaught exceptions, then close gracefully. The people reporting force closes aren't getting to any of that, even though it is the first thing set in the application's main task constructor, and everything is wrapped in try/catches throughout. They are also reporting that there is no "Send Report" option in the force close popup (providing the Developer Console error reports), so I have absolutely no way of knowing what the problem is.
Uses Android 2.0, with android:minSdkVersion="5". Only Permission required is INTERNET.
(on Android market as 'Fortunes of War FREE' if you want to test)
I'm a bit surprised about the missing "Send report" button. What API level did you build the game with? I usually build the level with your minimum API level to make sure you're not using any API calls beyond that, but then switch back to the highest API level so you can use functionality like "install to SD".
I'm sure there's at least one user who wrote you a mail. Can you ask them to install LogCollector and mail you the log?
Btw, in general, I wouldn't use Thread.setDefaultUncaughtExceptionHandler so there IS the option to send a report. (It's ominously missing in your case, but normally, it should be there.)
Btw btw, the exception handler applies to the current thread. If you have an OpenGL app, maybe the crash happens in the GL thread?
I'm not sure if I understood you correctly, but as far as I know Android only shows that report dialog if you use its default UncaughtExceptionHandler.
Try this:
In your UncaughtExceptionHander's constructor, call Thread.getDefaultUncaughtExceptionHandler and save the returned object in a variable (let's call it defaultHandler). In your Handler's uncaughtException() do the things you want to do, and then call defaultHandler.uncaughtException() afterwards.
Maybe something you should know:
In my experience, your Context isn't functional anymore at uncaughtException(). So, you can't send broadcasts, etc anymore.
By the way, if you really wrapped everything in try/catch, that could be the reason why error reporting doesn't work as expected? :P
Good luck
Tom
Perhaps the force closes are caused by stalls, rather than exceptions. Users may not notice the difference. This kind of problem can occur more often if users have CPU hogging services running at the same time as your application, which explains why you're not seeing the issue in your testing.
Permission Internet sounds a lot like you try to transfer data from the net, which is very fast in your local LAN, but all of a sudden becomes slow (and time consuming) when people try this over their GSM connections.
If you then do the data transfer in the UI thread, this one is blocked and the system detects the block - but then this should end up in a "Did not respond" -- but then I've seen one user report an error with in the market on my app that was such a slow down cause.

Why would an android user report "Force quits every time I load"?

I'm trying to guess why a user would report "Force quits every time I load"
The problem does not occur for all users, especially not me.
The system constructs a database when it first loads. I suspect that user's phone does not have enough memory.
Questions:
How can I verify that the system has enough memory to store a small database?
What else might cause a user's particular system to force quit on startup?
Wrong answers or things I've tried thus far:
The user's hardware is probably different than mine
The user's software and available memory is likely different as well
The data is already loading in its own thread, with a progress dialog showing
Add some smarts to your app to send you stack traces when the app crashes in the field. That'll narrow down the specific problem and can help you tailor your efforts to clear it up.
Sounds quite odd, does a freshly booted phone give the same error?
Also ask the user to check available storage, might be out if space.
If the UI thread gets frozen for a period of time, then it will show that dialog. Try running the task in the background using an AsyncTask.
Edit: I'm assuming it's this error message.

Categories

Resources