App not closing properly, causing multiple issues..

jtthjtth Member ✭✭
edited June 24 in Xamarin.Android

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.

Tagged:

Answers

  • LeonLuLeonLu Member, Xamarin Team Xamurai

    Do you want to remove the item of app from the recent app list when the app closed? You can try to add this FLAG_ACTIVITY_EXCLUDE_FROM_RECENTSflags to the Intent like this thread. https://stackoverflow.com/a/13385366/10627299

  • jtthjtth Member ✭✭
    edited June 25

    @LeonLu said:
    Do you want to remove the item of app from the recent app list when the app closed? You can try to add this FLAG_ACTIVITY_EXCLUDE_FROM_RECENTSflags to the Intent like this thread. https://stackoverflow.com/a/13385366/10627299

    Yes, initially. But I want to solve the real problem. When navigating between open apps and then back to our app it shows the initial SplashActivity and then the MainActivity. After this parts of our UI are not functioning properly. Is there a proper way to handle navigating back to an app?

    *EDIT: Well- have more testing to do but for some reason data loaded into our app from Azure blobs was cleared or not saved/stored and then not restored properly in OnResume when navigating back to our app. It looks like adding a simple reload Azure data call in OnResume() in our MainActivity fixed an anomalous UI bug...

    Also running a StopServices() call in OnStop() and an StartServices() call in OnResume() to hopefully fix bluetooth errors we were seeing when navigating back to our app. Will update on this.

Sign In or Register to comment.