Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Swiping away app with foreground service doesn't stop the app

$
0
0
I have a Xamarin.Forms application that I have just added a Xamarin.Android foreground service to. This service monitors location in the background.

When I swipe the app away, my override of OnTaskRemoved gets called and I stop the foreground service then StopSelf. I confirm the service is no longer running by looking in the developer section of my phone under running services. But my debugger in visual Studio stays connected and continues to show the app running.

When I go into the list of apps on my phone, I am able to push force close, which tells me the app really has not stopped. If I completely remove the service from my application, the debugger disconnects and the app is fully killed.

I saw some posts on StackOverflow that allude to issues with services not stopping when they are tied to monitoring location with native Droid Java development if certain things are not properly cleaned up, so I created a new service and all it does it update a the notification with current time. It has the same issue.

This is problematic for me because when I reopen the application after swiping it away, it shows our splash screen then takes me to our login screen. As part of user login, we create a Session object. When the user logs back in, it creates a second Session object -- it seems the first is still in memory. I have confirmed this because I put a static variable in my Session class, and it is incremented each time I open the application.

So I'd like to know if this behavior is expected. I'd also like to know if there is a proper way to handle objects that are created after log in if the app is swiped, but doesn't completely die like in this scenario.

Viewing all articles
Browse latest Browse all 204402

Trending Articles