From cd346b6005623d08ffc287715301901f43650856 Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Sat, 26 Oct 2019 21:09:21 +0200 Subject: [PATCH] Use SharedPreferences.apply() rather than commit(), as the latter blocks on I/O. --- oeffi/src/de/schildbach/oeffi/OeffiMainActivity.java | 6 +++--- .../src/de/schildbach/oeffi/stations/StationsActivity.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/oeffi/src/de/schildbach/oeffi/OeffiMainActivity.java b/oeffi/src/de/schildbach/oeffi/OeffiMainActivity.java index f2dfdf2..cb3b3ee 100644 --- a/oeffi/src/de/schildbach/oeffi/OeffiMainActivity.java +++ b/oeffi/src/de/schildbach/oeffi/OeffiMainActivity.java @@ -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(), diff --git a/oeffi/src/de/schildbach/oeffi/stations/StationsActivity.java b/oeffi/src/de/schildbach/oeffi/stations/StationsActivity.java index 88b988e..5aef605 100644 --- a/oeffi/src/de/schildbach/oeffi/stations/StationsActivity.java +++ b/oeffi/src/de/schildbach/oeffi/stations/StationsActivity.java @@ -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 getStations() {