My question is somewhat similar to this one, but I have more specific needs. Here we go:
In my Android apps, I want to add the functionality of saving the Logcat into a log file. So when a user reports a problem with my apps, I can ask for the log file. Saving the Logcat into a file is quite straightforward, as discussed here. Now the question is: when to save?
My current plan is to call logcat -c
in my app's onCreate, and save Logcat in onStop. By calling logcat -c
up front, I remove information unrelated to my app.
However, I see two flaws in my plan:
If a user installs two different apps from me, there is a chance that the second one gets started before the first finishes. Because onStop of the 1st app is not called, the Logcat is not yet saved. The
logcat -c
in the 2nd app's onCreate will wipe out any logging information for the 1st app up to that point.Even if only one app is running, its onStop is not called if it crashes. Or is it? I checked the activity's life cycle, but can't tell for sure whether or not onStop is called in the case of a crash. Assuming it is not called, then this beats my purpose. I need the Logcat to understand why my app crashes, but the Logcat is not saved if it crashes.
Any thoughts and/or suggestions? Thanks in advance!