gcash / android-neutrino

Android mobile wallet using the bchwallet/neutrino backend
9 stars 9 forks source link

Settings refactor #26

Closed gubatron closed 5 years ago

gubatron commented 5 years ago

When/If you merge this, I've found a potential ANR on your MainActivity when you create the Settings object.

Doing this at MainActivity::onCreate can cause Android apps to freeze on startup:

        SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
        this.settings = new Settings(sharedPref);

The IO performed by PreferenceManager.getDefaultSharedPreferences(this) leads to common ANR reports in my experience, I believe your NotificationService makes another call when the service is created, this can lead to race conditions that trigger the ANR.

It's better to do that in a background thread and start accessing preferences once available. Perhaps you've not seen this reports yet, but they certainly popped up a lot for us after several thousand instances in the wild.

Again, if you merge this let me know what you think, I'd be happy to do this fix for you.

gubatron commented 5 years ago

great success borat

Thanks fellas!