Issue
I created a custom application class to keep global informations of my app.
I need to get those informations back after my application restarts from a crash. I don't need to store those informations in disk because is just info from the user current session, but if the app crashed, I should start exactly where the user was before the crash.
I thought in two ways to solve my problem: 1-Track the variables changes and always persist it in the SharedPreferences 2-Always save then in the activity saveInstance and retain then from the savedInstanceBundle
The problem with the solution 1 is an overhead in every change. The problem with solution 2 is that I need to serialize every info.
Do you guys know any other way to solve that problem? I only need to store when the app crashs and load back after starting from a crash. Just in those two scenarios.
Solution
I'm currently using the following code to track whenever my app crashes, so i can show a better crash screen to the user, and it also allows me to send information about the crash to my server for later debugging.
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
//Get information and save the information
}
});
But just as a warning, you need to set this in every Activity / Service you create for it to be 100% effective.
Personally i have 1 base class for all my Activities, and 1 for all my Services, and then those classes implement the UncaughtExceptionHandler, so that can save ALOT of headeche and code copy-paste.
Answered By - Moonbloom
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.