<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Compose, lifecycle and object already owned in Kotlin Maps SDK Questions</title>
    <link>https://community.esri.com/t5/kotlin-maps-sdk-questions/compose-lifecycle-and-object-already-owned/m-p/1336579#M240</link>
    <description>&lt;P&gt;Had this problem too with Scenes, the sample apps in arcgis-maps-sdk-kotlin-samples are missing:&lt;/P&gt;&lt;LI-CODE lang="kotlin"&gt;mapView.onDestroy(lifecycleOwner) or sceneView.onDestroy(lifecycleOwner) view calls. &lt;/LI-CODE&gt;&lt;P&gt;It only appeared to matter once I changed the viewmodels to hiltViewModels.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 10 Oct 2023 15:04:40 GMT</pubDate>
    <dc:creator>LeighWoolley</dc:creator>
    <dc:date>2023-10-10T15:04:40Z</dc:date>
    <item>
      <title>Compose, lifecycle and object already owned</title>
      <link>https://community.esri.com/t5/kotlin-maps-sdk-questions/compose-lifecycle-and-object-already-owned/m-p/1330505#M231</link>
      <description>&lt;P&gt;Hi, we use ArcGISMap in an AndroidView. When we recompose the composition so that the map is not rendered anymore and recompose again&amp;nbsp; so that the map is displayed again, I get the common error "object already owned" for the wmts map we assign to the ArcGISMap. I understand that.&lt;/P&gt;&lt;P&gt;What I do to avoid that is to use the onRelease callback from the AndroidView to set the map to null.&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;onRelease = &lt;/SPAN&gt;&lt;SPAN&gt;{ &lt;/SPAN&gt;view &lt;SPAN&gt;-&amp;gt;&lt;BR /&gt;&lt;/SPAN&gt;    &lt;SPAN&gt;// Required, if not set to null, map object will be marked&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;    // as owned when retuning from zoom view&lt;BR /&gt;&lt;/SPAN&gt;    view.&lt;SPAN&gt;map &lt;/SPAN&gt;= &lt;SPAN&gt;null&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;This works for the recomposition part. But when I finish() the Activity, I get the following error in 50% of my tests. This seems to me like the map may not be null.&lt;/P&gt;&lt;P&gt;&lt;EM&gt;java.lang.RuntimeException: Unable to destroy activity {de.bwi.kvib.mobile.dev/de.bwi.kvib.mobile.feature.pois.PoiComposeActivity}: java.lang.NullPointerException: Null pointer.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;...&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Caused by: java.lang.NullPointerException: Null pointer.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;...&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Caused by: com.arcgismaps.exceptions.ArcGISExceptionImpl: message=Null pointer., additionalMessage=object cannot be null., errorCode=1&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Can you propose a solution to either avoid that NPE or unassign the map from the ArcGISMap?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 07:27:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/kotlin-maps-sdk-questions/compose-lifecycle-and-object-already-owned/m-p/1330505#M231</guid>
      <dc:creator>padmalcom</dc:creator>
      <dc:date>2023-09-20T07:27:56Z</dc:date>
    </item>
    <item>
      <title>Re: Compose, lifecycle and object already owned</title>
      <link>https://community.esri.com/t5/kotlin-maps-sdk-questions/compose-lifecycle-and-object-already-owned/m-p/1330613#M232</link>
      <description>&lt;P&gt;Hi, we have a reference implementation of using the MapView in an AndroidView you can refer to &lt;A href="https://github.com/Esri/arcgis-maps-sdk-kotlin-toolkit/blob/main/toolkit/composable-map/src/main/java/com/arcgismaps/toolkit/composablemap/ComposableMap.kt" target="_self"&gt;here&amp;nbsp;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;In this reference you will see two things that ensure proper internal management of the MapView and its reference to the ArcGISMap.&lt;/P&gt;&lt;P&gt;1) Your activity should be registered as a LIfecycleObserver, and in your composable yo can get a handle to the LIfecycleOwner by calling&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="kotlin"&gt;val lifecycleOwner = LocalLifecycleOwner.current&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) Once you have this lifecycleOwner, you can set up a DisposableEffect to run when the AndroidView leaves the composition, and properly disposes the MapView.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="kotlin"&gt;DisposableEffect(Unit) {
    onDispose {
        mapView.onDestroy(lifecycleOwner)
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This will do several things internally to gracefully release resources, including setting the map to null.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 14:14:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/kotlin-maps-sdk-questions/compose-lifecycle-and-object-already-owned/m-p/1330613#M232</guid>
      <dc:creator>SorenRoth</dc:creator>
      <dc:date>2023-09-20T14:14:29Z</dc:date>
    </item>
    <item>
      <title>Re: Compose, lifecycle and object already owned</title>
      <link>https://community.esri.com/t5/kotlin-maps-sdk-questions/compose-lifecycle-and-object-already-owned/m-p/1330615#M233</link>
      <description>&lt;P&gt;Hi Soren, thank you for the&amp;nbsp; fast reply. The example is what I was looking for.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 14:19:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/kotlin-maps-sdk-questions/compose-lifecycle-and-object-already-owned/m-p/1330615#M233</guid>
      <dc:creator>padmalcom</dc:creator>
      <dc:date>2023-09-20T14:19:37Z</dc:date>
    </item>
    <item>
      <title>Re: Compose, lifecycle and object already owned</title>
      <link>https://community.esri.com/t5/kotlin-maps-sdk-questions/compose-lifecycle-and-object-already-owned/m-p/1336579#M240</link>
      <description>&lt;P&gt;Had this problem too with Scenes, the sample apps in arcgis-maps-sdk-kotlin-samples are missing:&lt;/P&gt;&lt;LI-CODE lang="kotlin"&gt;mapView.onDestroy(lifecycleOwner) or sceneView.onDestroy(lifecycleOwner) view calls. &lt;/LI-CODE&gt;&lt;P&gt;It only appeared to matter once I changed the viewmodels to hiltViewModels.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2023 15:04:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/kotlin-maps-sdk-questions/compose-lifecycle-and-object-already-owned/m-p/1336579#M240</guid>
      <dc:creator>LeighWoolley</dc:creator>
      <dc:date>2023-10-10T15:04:40Z</dc:date>
    </item>
  </channel>
</rss>

