Following is my code
@NonNull
private T readLocalResource() {
synchronized (this) {
if (data == null) {
String resourceAsString = sharedPreferences.getString(key, null);
if (TextUtils.isEmpty(resourceAsString)){
data = initialResource;
}
else {
data = parseJson(resourceAsString);
}
}
return data;
}
}
Above code is causing ANR in few cases following is the ANR log
"main" tid=1 Blocked
at com.mypackage.ResourceCache.readLocalResource (MyResourceCache.java:101)
at com.mypackage.ResourceCache.get (MyResourceCache.java:73)
at com.mypackage.datacollector.DataLayer.lambda$createRegistry$5 (DataLayer.java:73)
How to fix this?