When we close our app by navigating to the recently used app list and swiping away our specific app or by hitting the "Close all" button it resurrects in some weird state that isn't actually usable. When in this state the app icon has a red 1 badge icon.
So in short what we are seeing is that on swiping an app "closed" the app is still alive. It can only be closed by going to Settings --> Apps, selecting the app, and tapping "Force stop"!
The below seems to work, but ONLY when connected to a debugger via USB. When running from the device (even with this "Force stop" like code) we are still seeing the app after closing it from the recent app list.
ActivityManager am = (ActivityManager)GetSystemService(
Context.ActivityService);
am.KillBackgroundProcesses("TurkeyanaCall.TurkeyanaCall");
Android.OS.Process.SendSignal(Android.OS.Process.MyPid(), Signal.Kill);
Is there any solution to this? This bugged state causes our UI to break and bluetooth interactions to be faulty.
*EDIT: tried clearing services and using System.exit(0)
but still seemingly encountering the same error state
ActivityManager am = (ActivityManager)GetSystemService(
Context.ActivityService);
IList<ActivityManager.RunningServiceInfo> runningServices = am.GetRunningServices(Java.Lang.Integer.MaxValue);
int pid = Process.MyPid();
foreach (ActivityManager.RunningServiceInfo serviceInfo in runningServices)
{
if (serviceInfo.Pid == pid)
{
try
{
Intent intent = new Intent();
intent.SetComponent(serviceInfo.Service);
_Instance.StopService(intent);
}
catch (Java.Lang.Exception ex)
{
Console.WriteLine(ex.Message);
}
catch (System.Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
am.KillBackgroundProcesses("TurkeyanaCall.TurkeyanaCall");
Android.OS.Process.SendSignal(Android.OS.Process.MyPid(), Signal.Kill);
Java.Lang.JavaSystem.Exit(0);