Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

avoid race condition when calling getMapAsync from OnMapReadyIdlingResource #12308

Merged
merged 1 commit into from
Jul 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down