Use SharedPreferences.apply() rather than commit(), as the latter blocks on I/O.

This commit is contained in:
Andreas Schildbach 2019-10-26 21:09:21 +02:00
parent c0eabf93b1
commit cd346b6005
2 changed files with 4 additions and 4 deletions

View file

@ -122,7 +122,7 @@ public abstract class OeffiMainActivity extends OeffiActivity {
if (prefsGetNetwork() == null) {
NetworkPickerActivity.start(this);
prefs.edit().putLong(Constants.PREFS_KEY_LAST_INFO_AT, now).commit();
prefs.edit().putLong(Constants.PREFS_KEY_LAST_INFO_AT, now).apply();
downloadAndProcessMessages(prefsGetNetwork());
} else if (versionCode != lastVersionCode) {
@ -576,9 +576,9 @@ public abstract class OeffiMainActivity extends OeffiActivity {
showDialog(DIALOG_MESSAGE, message);
final long now = System.currentTimeMillis();
messagesPrefs.edit().putLong(id, now).commit();
messagesPrefs.edit().putLong(id, now).apply();
if ("info".equals(action))
prefs.edit().putLong(Constants.PREFS_KEY_LAST_INFO_AT, now).commit();
prefs.edit().putLong(Constants.PREFS_KEY_LAST_INFO_AT, now).apply();
});
} else {
log.info("Got '{}: {}' when fetching message from: '{}'", response.code(),

View file

@ -1235,7 +1235,7 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
final StringBuilder p = new StringBuilder();
for (final Product product : products)
p.append(product.code);
prefs.edit().putString(Constants.PREFS_KEY_PRODUCT_FILTER, p.toString()).commit();
prefs.edit().putString(Constants.PREFS_KEY_PRODUCT_FILTER, p.toString()).apply();
}
public final List<Station> getStations() {