Can someone advise how to avoid having the below ANR reports in Google Play Console:
Broadcast of Intent { act=android.intent.action.SCREEN_OFF  flg=0x50000010 launchParam=MultiScreenLaunchParams { mDisplayId=0  mFlags=0 } (has extras) }
"main" prio=5 tid=1 Native   | group="main" sCount=1 dsCount=0 obj=0x761cd7a0 self=0xec405400   | sysTid=516 nice=0 cgrp=default sched=0/0 handle=0xef977534   | state=S schedstat=( 30085039666 3460567380 28197 ) utm=2577 stm=431 core=4 HZ=100   | stack=0xff2a5000-0xff2a7000 stackSize=8MB   | held mutexes=    native: pc 00000000000174b8  /system/lib/libc.so (syscall+28)   native: pc 0000000000046fab  /system/lib/libc.so (_ZL24__pthread_cond_timedwaitP23pthread_cond_internal_tP15pthread_mutex_tbPK8timespec+102)   native: pc 00000000001de538  /data/app/com.xxx.android-1/lib/arm/libmonosgen-2.0.so (???)   at mono.java.lang.RunnableImplementor.n_run (Native method)   at mono.java.lang.RunnableImplementor.run (RunnableImplementor.java:30)   at android.os.Handler.handleCallback (Handler.java:751)   at android.os.Handler.dispatchMessage (Handler.java:95)   at android.os.Looper.loop (Looper.java:154)   at android.app.ActivityThread.main (ActivityThread.java:6692)   at java.lang.reflect.Method.invoke! (Native method)   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1468)   at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1358)
I am not sure what causes these, I can only assume that they might be caused by a lengthy save game operation which I execute inside my Game.Stopped event handler:
         public void SaveGame()        {             if (g != null && g.IsRunning)             {                 try                 {                     CreateDirectoryForFilePath(_savedGameFilePath);                     if (g.GameType != 0)                     {                         using (var fs = File.Open(_savedGameFilePath, FileMode.Create))                         {                             g.SaveGame(fs, saveDebugInfo: true);                         }                     }                     else                     {                         File.Copy(_newGameFilePath, _savedGameFilePath, true);                     }                 }                 catch (Exception e)                 {                     System.Diagnostics.Debug.WriteLine(string.Format("Cannot save game\n{0}", e.Message));                 }             }         }
Can someone confirm what is the cause and/or suggest a workaround? I think that calling SaveGame on a separate thread is probably not the right thing to do given that my application is about to be paused, right? Any help is greatly appreciated!