Home > Blockchain >  Android kills my app every time I go to home screen
Android kills my app every time I go to home screen

Time:12-10

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?

CodePudding user response:

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.

  • Related