[android] - avoid race condition when calling getMapAsync from OnMapReadyIdlingResource

This commit is contained in:
tobrun
2018-07-04 17:04:39 +02:00
committed by Tobrun
parent d734f670e8
commit 9920b25af3

View File

@@ -1,6 +1,8 @@
package com.mapbox.mapboxsdk.testapp.utils;
import android.app.Activity;
import android.os.Handler;
import android.support.annotation.WorkerThread;
import android.support.test.espresso.IdlingResource;
import com.mapbox.mapboxsdk.maps.MapView;
@@ -14,14 +16,17 @@ public class OnMapReadyIdlingResource implements IdlingResource, OnMapReadyCallb
private MapboxMap mapboxMap;
private IdlingResource.ResourceCallback resourceCallback;
@WorkerThread
public OnMapReadyIdlingResource(Activity activity) {
try {
Field field = activity.getClass().getDeclaredField("mapView");
field.setAccessible(true);
((MapView) field.get(activity)).getMapAsync(this);
} catch (Exception err) {
throw new RuntimeException(err);
}
new Handler(activity.getMainLooper()).post(() -> {
try {
Field field = activity.getClass().getDeclaredField("mapView");
field.setAccessible(true);
((MapView) field.get(activity)).getMapAsync(OnMapReadyIdlingResource.this);
} catch (Exception err) {
throw new RuntimeException(err);
}
});
}
@Override