Performance: Keep reference to sharedPreferences.

So far, we opened the SharedPreferences very often, which is very slow; also happened in the UI thread a lot.

Fixes #642.
This commit is contained in:
Dennis Guse
2021-03-15 12:01:32 +01:00
committed by GitHub
parent eebc33f60c
commit 15fbd90ca4
39 changed files with 355 additions and 344 deletions
@@ -2,6 +2,7 @@ package de.dennisguse.opentracks.util;
import android.content.ContentResolver;
import android.content.Context;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.provider.DocumentsContract;
@@ -28,9 +29,10 @@ public class ExportUtils {
private static final String TAG = ExportUtils.class.getSimpleName();
public static void postWorkoutExport(Context context, Track track, ExportServiceResultReceiver resultReceiver) {
if (PreferencesUtils.shouldInstantExportAfterWorkout(context)) {
TrackFileFormat trackFileFormat = PreferencesUtils.getExportTrackFileFormat(context);
DocumentFile directory = PreferencesUtils.getDefaultExportDirectoryUri(context);
SharedPreferences sharedPreferences = PreferencesUtils.getSharedPreferences(context);
if (PreferencesUtils.shouldInstantExportAfterWorkout(sharedPreferences, context)) {
TrackFileFormat trackFileFormat = PreferencesUtils.getExportTrackFileFormat(sharedPreferences, context);
DocumentFile directory = PreferencesUtils.getDefaultExportDirectoryUri(sharedPreferences, context);
ExportService.enqueue(context, resultReceiver, track.getId(), trackFileFormat, directory.getUri());
}