0

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.

4

1 に答える 1

1

現在、次のコードを使用して、アプリがクラッシュするたびに追跡しています。これにより、より適切なクラッシュ画面をユーザーに表示できます。また、後でデバッグするためにクラッシュに関する情報をサーバーに送信することもできます。

Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
    @Override
    public void uncaughtException(Thread thread, Throwable ex) {
        //Get information and save the information 
    }
});

ただし、警告として、作成するすべてのアクティビティ/サービスでこれを設定して、100% 有効にする必要があります。

個人的には、すべてのアクティビティに対して 1 つの基本クラスがあり、すべてのサービスに対して 1 つの基本クラスがあり、これらのクラスは UncaughtExceptionHandler を実装しているため、頭を悩ませることとコードのコピーと貼り付けを大幅に節約できます。

于 2015-10-03T01:19:25.027 に答える