diff options
author | tobrun <tobrun.van.nuland@gmail.com> | 2018-07-04 17:04:39 +0200 |
---|---|---|
committer | Tobrun <tobrun@mapbox.com> | 2018-07-05 11:11:51 +0200 |
commit | 9920b25af3c2f70bb22ed65885db2dd10dc10fe0 (patch) | |
tree | 71a2fe06697901ddaf29b6cf0705bca87a578f78 /platform/android | |
parent | d734f670e8127c7600beb6dad7b7f08b1401e7c0 (diff) | |
download | qtlocation-mapboxgl-9920b25af3c2f70bb22ed65885db2dd10dc10fe0.tar.gz |
[android] - avoid race condition when calling getMapAsync from OnMapReadyIdlingResource
Diffstat (limited to 'platform/android')
-rw-r--r-- | platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/utils/OnMapReadyIdlingResource.java | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/utils/OnMapReadyIdlingResource.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/utils/OnMapReadyIdlingResource.java index 0e2e4587ee..4e4c69620a 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/utils/OnMapReadyIdlingResource.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/utils/OnMapReadyIdlingResource.java @@ -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 |