1

I observed the following behavior:

  • if I switch to another app via Recent button and then switch back to my app, everything works fine
  • if I press the Home button and then open my app from the app drawer, my app is restarted

The Android version doesn't seem to matter. Rather the type of installation makes a difference. If I copy the apk onto the device and install it manually, I get the above behavior. If I instead use Visual Studio and build for Release/Debug it works without problems. It should be the same apk file!

Device log brings up the following log, when the app is killed:

12-03 15:29:36.402 10719 10719 I SomeApp: ================ Xamarin: OnSleep()
12-03 15:29:36.410  1350  3999 E WindowManager: win=Window{cf46d1f u0 com.company.someapp/crc64cf5f37a7af23dc58.MainActivity} destroySurfaces: appStopped=true win.mWindowRemovalAllowed=false win.mRemoveOnExit=false win.mViewVisibility=8 caller=com.android.server.wm.AppWindowToken.destroySurfaces:1248 com.android.server.wm.AppWindowToken.destroySurfaces:1229 com.android.server.wm.AppWindowToken.notifyAppStopped:1284 com.android.server.wm.ActivityRecord.activityStoppedLocked:2776 com.android.server.wm.ActivityTaskManagerService.activityStopped:2512 android.app.IActivityTaskManager$Stub.onTransact:2280 android.os.Binder.execTransactInternal:1056 
12-03 15:29:36.410  1350  3999 I WindowManager: Destroying surface Surface(name=com.company.someapp/crc64cf5f37a7af23dc58.MainActivity$_10719)/@0xe1a35ad called by com.android.server.wm.WindowStateAnimator.destroySurface:1834 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:733 com.android.server.wm.WindowState.destroySurfaceUnchecked:3642 com.android.server.wm.WindowState.destroySurface:3616 com.android.server.wm.AppWindowToken.destroySurfaces:1248 com.android.server.wm.AppWindowToken.destroySurfaces:1229 com.android.server.wm.AppWindowToken.notifyAppStopped:1284 com.android.server.wm.ActivityRecord.activityStoppedLocked:2776 
12-03 15:29:36.411   820  1120 I Layer   : id=2656 removeFromCurrentState com.company.someapp/crc64cf5f37a7af23dc58.MainActivity$_10719#0 (77)
12-03 15:29:36.413   820  1120 I SurfaceFlinger: id=2656 Removed com.company.someapp/crc64cf5f37a7af23dc58.MainActivity$_10719#0 (77)

Is there a wrong setting in the AndroidManifest.xml for launching the application? I'm using android:launchMode="singleTop" for my application. I also checked the battery saving, but the behavior doesn't change. RAM usage is also ok. This happens on different Samsung devices.

How can I find out the cause for this?

testing
  • 19,681
  • 50
  • 236
  • 417
  • This could be due to a myriad of reasons. Do you have "Don't keep Activities" dev option on? Are you sure the device has enough memory to handle both apps at the same time? Is this happening on release builds? Unfortunately, I'm not a Xamarian dev so I cannot help much on that front! – Ivan Garza Dec 03 '21 at 18:28
  • 1
    I tried to turn off developer settings, but it's the same behavior. The device manager says that there are 1.6 GB left, so this shouldn't be an issue (my app uses ~200 MB). Yes, it's happening on Release Build. My guess would be that there is a Android misconfiguration or something like that. Thanks for your comment! – testing Dec 03 '21 at 18:34
  • 1
    `This happens on different Samsung devices.` Have you tested it on other devices? – Jessie Zhang -MSFT Dec 06 '21 at 06:31

2 Answers2

4

It's an issue with the Samsung launcher, when you freshly installed the sideloaded app. If you tap on "open" after installation the issue occurs. It seems that it has to do with the Intent type and the package installer. The app is not killed, rather a new instance is created (see here or here for similar problems and try the back button!). And it depends on how an app is opened. The Xamarin solution posted here doesn't work for me.

Because it's more a minor issue, which doesn't happen to often in real life, the solution is to not open the app directly after installation with the shown dialog. Instead user the app drawer and then everything works fine. Or use another device manufacturer like LG, which doesn't have this issue.

testing
  • 19,681
  • 50
  • 236
  • 417
0

Check that you don't have checked the option "Don’t Keep Activities" in developer settings.

rockdaswift
  • 9,613
  • 5
  • 40
  • 46