Select to view content in your preferred language

Facing ANR when get identify graphic overlay

818
2
Jump to solution
02-08-2023 01:12 AM
MinhPham92
Emerging Contributor

Hi all,

I am facing some ANR with my implement as below and the log for ANR point to our Arcgis map when getting the identify graphic overlay.
Could someone help to check for that?
Please let me know if you need further information

Implementation for touching listener:

onTouchListener =
object : DefaultMapViewOnTouchListener(context, this) {
override fun onSingleTapConfirmed(event: MotionEvent): Boolean {
val screenPoint =
android.graphics.Point(event.x.roundToInt(), event.y.roundToInt())
val identifyGraphic = mMapView.identifyGraphicsOverlayAsync(
graphicsOverlay,
screenPoint,
10.0,
false,
Int.MAX_VALUE
)

try {
val identifyGraphicsOverlayResult = identifyGraphic.get()
val graphics = identifyGraphicsOverlayResult.graphics
} catch(e: Exception){
// print log here
}
return super.onSingleTapConfirmed(event)


ANR log report:

libc.so
syscall + 28
1. libc.so
__futex_wait_ex(void volatile*, bool, int, bool, timespec const*) + 144
2. libc.so
pthread_cond_wait + 76
3. split_config.arm64_v8a.apk
std::__ndk1::condition_variable::wait(std::__ndk1::unique_lock<std::__ndk1::mutex>&) + 20
4. split_config.arm64_v8a.apk
(Missing BuildId 4d4a58df2fe1ee0c204b45b49389f1966c646580)
5. split_config.arm64_v8a.apk
(Missing BuildId 4d4a58df2fe1ee0c204b45b49389f1966c646580)
6. split_config.arm64_v8a.apk
(Missing BuildId 4d4a58df2fe1ee0c204b45b49389f1966c646580)
7. split_config.arm64_v8a.apk
(Missing BuildId 4d4a58df2fe1ee0c204b45b49389f1966c646580)
8. split_config.arm64_v8a.apk
(Missing BuildId 4d4a58df2fe1ee0c204b45b49389f1966c646580)
9. split_config.arm64_v8a.apk
(Missing BuildId 4d4a58df2fe1ee0c204b45b49389f1966c646580)
10. split_config.arm64_v8a.apk
RT_Task_get + 32
11. split_config.arm64_v8a.apk
Java_com_esri_arcgisruntime_internal_jni_CoreTask_nativeGet + 20

com.esri.arcgisruntime.internal.jni.CoreTask.nativeGet (SourceFile)

com.esri.arcgisruntime.internal.jni.CoreTask.f (SourceFile:1)

com.esri.arcgisruntime.internal.concurrent.b.get (SourceFile:23)

.......setOnMapViewTouchListener$1.onSingleTapConfirmed
 
 



 

 

0 Kudos
1 Solution

Accepted Solutions
Hudson_Miears
Occasional Contributor

Hello! It looks like the ANR is most likely caused by this line:

val identifyGraphicsOverlayResult = identifyGraphic.get()

 ListenableFuture.get() will block the current thread until the result is available. In 100.15 and previous versions of the SDK, we recommend you use a callback pattern instead:

val screenPoint = android.graphics.Point(event.x.roundToInt(), event.y.roundToInt())
val identifyGraphicsOverlayResultFuture = mMapView.identifyGraphicsOverlayAsync(
  graphicsOverlay,
  screenPoint,
  10.0,
  false,
  Int.MAX_VALUE
)

identifyGraphicsOverlayResultFuture.addDoneListener {
  try {
    val identifyGraphicsOverlayResult = identifyGraphicsOverlayResultFuture.get()
    val graphics = identifyGraphicsOverlayResult.graphics
  } catch(e: Exception){
    // print log here
  }
}


For more information, you could check out this sample. It doesn't use MapView.identifyGraphicsOverlayAsync(), but it does use the same pattern.

Hope this helps!

View solution in original post

2 Replies
Hudson_Miears
Occasional Contributor

Hello! It looks like the ANR is most likely caused by this line:

val identifyGraphicsOverlayResult = identifyGraphic.get()

 ListenableFuture.get() will block the current thread until the result is available. In 100.15 and previous versions of the SDK, we recommend you use a callback pattern instead:

val screenPoint = android.graphics.Point(event.x.roundToInt(), event.y.roundToInt())
val identifyGraphicsOverlayResultFuture = mMapView.identifyGraphicsOverlayAsync(
  graphicsOverlay,
  screenPoint,
  10.0,
  false,
  Int.MAX_VALUE
)

identifyGraphicsOverlayResultFuture.addDoneListener {
  try {
    val identifyGraphicsOverlayResult = identifyGraphicsOverlayResultFuture.get()
    val graphics = identifyGraphicsOverlayResult.graphics
  } catch(e: Exception){
    // print log here
  }
}


For more information, you could check out this sample. It doesn't use MapView.identifyGraphicsOverlayAsync(), but it does use the same pattern.

Hope this helps!

MinhPham92
Emerging Contributor

Really thanks Hudson_Miears, I was thinking about the Future task which will be the cause of ANR and intended to move it into the background. But with your solution, I just need to use existing function.

0 Kudos