Select to view content in your preferred language

Android: Map is frozen when resuming app

1557
9
03-20-2024 12:17 PM
Labels (3)
FelicityRhone
Occasional Contributor

I think this only occurs on Samsung phones, on Android 14.

It's a problem in our production app, but also easy to reproduce in a new Maui app (I shared my demo app here https://github.com/Felicity-R/EsriMapTest/issues).

Repro steps:

  1. Create a new Maui app (.Net 8 )
  2. Add reference to Esri Maps SDK (200.3). Add .UseArcGISRuntime() in MauiProgram and set up API key.
  3. Replace default controls in MainPage with a MapView - set up a basemap and load map.
  4. Launch the app on Android. Observe that the map loads and is interactable.
  5. Switch to a different Android app so your Maui app is backgrounded. Wait about 10 seconds\*.
  6. Switch back to the Maui app. The bug: Observe that the map is visible but won't visibly respond to interaction - is frozen. If you rotate your device (e.g. from portrait to landscape) then the map will 'wake up' and be interactable again.
  7. Extra info: If you have location display enabled, then the map will be blank/gray instead of just non-interactable, if the location indicator was in your extent when you backgrounded the app. Rotation still fixes it.

Possibly related to this issue someone reported in the Runtime SDK for Android: https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/map-is-freezed-when-switching...

\* watching the logs, I know the map will be frozen after I see this message come up while backgrounded:
[Choreographer] CoreRune.SYSPERF_ACTIVE_APP_BBA_ENABLE : stop animation in background states

9 Replies
FelicityRhone
Occasional Contributor

Oh yeah, and this also occurs in the older version of our app, using Xamarin Forms (5.0.0.2337) and Esri.ArcGISRuntime 100.15.2.

FelicityRhone
Occasional Contributor

I also wonder if this is connected to https://github.com/flutter/flutter/issues/139630 which people are saying might be an issue on Samsung's side? But if there's any kind of workaround that Esri or our team could implement that would be ideal.

0 Kudos
esp1rl
by
Occasional Contributor

I can report we're experiencing the same on Samsung devices.

TomášZachoval
Occasional Contributor

I also want to report this bug, on Samsung device. It often occurs after transitioning to the foreground.  After going to a new page and back when re-initializing the map view. The map view has started working again.

 

0 Kudos
aeldib
by
New Contributor

Esri has logged a bug for this issue:

BUG-000166099 Map view interactions freeze after returning to ArcGIS Maps SDK for .NET MAUI Android App on physical Samsung Galaxy devices with Android 14

As @FelicityRhone suggested, the issue is caused by a flutter/samsung bug.

The issue might be fixed in the Samsung's OneUI 6.1 patch, which should have been rolling out in the last couple of days. However, this isn't confirmed by users yet.

FelicityRhone
Occasional Contributor

My team was able to test this today on both a Samsung Galaxy Z Flip and a Samsung Galaxy Tab S8, both with Android 14, and with OneUI updated to 6.1.
Unfortunately, the bug is not resolved by the new version of OneUI.
We did do a test of an Android 15 beta a while back and that *does* seem to fix the issue. But with Android 14 it's still a problem.

TomášZachoval
Occasional Contributor

It should not be marked as resolved. Problem is still there. As I write in the post below.

TomášZachoval
Occasional Contributor

I confirm that the update to OneUI 6.1 did not resolve the bug. It is still appearing. You have to spend a few seconds outside of the app, and the MapView will freeze (going to background or web view).

I tried to reinitialize the map on onAppearingEvent, but that didn’t help. Is there any workaround or solution? This is a really big problem for mobile maps.

Tags (1)
esp1rl
by
Occasional Contributor

I found a workaround by altering the MapView layout on app resume.

public partial class App : Application
{
#if ANDROID
    protected override async void OnResume()
    {
        base.OnResume();

        // ISSUE: Map may be frozen when app is resumed
        // https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/map-is-freezed-when-switching-back-to-the-app-on/td-p/1378043
        // https://community.esri.com/t5/net-maps-sdk-questions/android-map-is-frozen-when-resuming-app/m-p/1404692

        if (MainPage is Shell { CurrentPage: MapPage { IsLoaded: true } mapPage })
        {
            // wait for the app to be resumed before applying fix
            await Task.Delay(TimeSpan.FromSeconds(1));

            mapPage.FixMapViewFreeze();
        }
    }
#endif
}

 

Then add this for the map page.

 

#if ANDROID
internal void FixMapViewFreeze()
{
    // apply a temporary margin to force a redraw
    MapView.Margin = new Thickness(0, 0, 0, 1);

    // wait for the UI thread to process the layout change and then reset the margin
    Dispatcher.DispatchDelayed(TimeSpan.FromMilliseconds(50), () => MapView.Margin = Thickness.Zero);
}
#endif