Automattic / simplenote-android

Simplenote for Android
https://simplenote.com
GNU General Public License v2.0
1.78k stars 301 forks source link

Application not responding (ANR) when creating the app #1535

Open danilo04 opened 2 years ago

danilo04 commented 2 years ago

We are getting ANR reports when the app is being created. The reports point to the callback Simplenote.onCreate(...) and specifically to Simplenote.getAccountInfo(). This is due to database queries done in the main thread.

A possible fix would be to make these calls in a different thread than the main thread:

class Simplenote {

 void onCreate(...) {
        ...
        AppLog.add(Type.DEVICE, getDeviceInfo());
        AppLog.add(Type.ACCOUNT, getAccountInfo());
        AppLog.add(Type.LAYOUT, DisplayUtils.getDisplaySizeAndOrientation(Simplenote.this));
}

Expected

The app starts without ANR problems.

Observed

The app crashes after 5 seconds.

Reproduced

Note: to reproduce this issue, we have to have slow queries. This is hard to do but has been observed in Sentry reports.

  1. Be sure the app is not running in the background
  2. Open the app

Device Make: Nokia Device Model: Nokia 7 plus Android Version: 10.0.0 Simplenote Version: 2.23.0