Call methods of GA on the main thread to avoid ConcurrentModificationException

This commit is contained in:
serso 2017-07-26 10:24:58 +02:00
parent 07b989f00e
commit 14ff42daf7

View File

@ -23,6 +23,7 @@
package org.solovyev.android.calculator;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
@ -52,6 +53,27 @@ import jscl.MathEngine;
public class CalculatorApplication extends android.app.Application implements SharedPreferences.OnSharedPreferenceChangeListener {
// delayed GA reporting in order to avoid initialization of GA on the main
// application thread and to postpone it as much as possible
private class GaInitializer extends AsyncTask<Void, Void, Ga> {
@NonNull
private final SharedPreferences prefs;
GaInitializer(@NonNull SharedPreferences prefs) {
this.prefs = prefs;
}
@Override
protected Ga doInBackground(Void... params) {
return ga.get();
}
@Override
protected void onPostExecute(@NonNull Ga ga) {
ga.reportInitially(prefs);
}
}
@Inject
@Named(AppModule.THREAD_INIT)
Executor initThread;
@ -149,11 +171,9 @@ public class CalculatorApplication extends android.app.Application implements Sh
@Override
public void run() {
warmUpEngine();
// delayed GA reporting in order to avoid initialization of GA on the main
// application thread and to postpone it as much as possible
ga.get().reportInitially(prefs);
}
});
new GaInitializer(prefs).executeOnExecutor(initThread);
}
private void warmUpEngine() {