0

If a foregrounded Android app is selected and swiped up to terminate the app in the windows tab, the background app continues to execute, and the UI window destroyed. Trying to generate a new window or popup, the app encounters an error. Is there a way to prevent the termination of the UI window?

Termination of the UI window being prevented is desired.

Marc George
  • 134
  • 1
  • 18
  • I doubt you can stop the termination. That would make it hard for a user to control what is running on their device. What error does the background app encounter? – ToolmakerSteve Aug 22 '23 at 22:30
  • The app is MAUI based using a popup when interaction is required. The error message is: Android.Views.WindowManagerBadTokenException 'Unable to add window – token android.os.BinderProxy@260c22b is not valid" I haven't found a way to replace the token with a valid one, hence this question. As a background service, the user has to go deeper into notifications to terminate the entire application. – Marc George Aug 22 '23 at 23:27
  • @MarcGeorge If you provide source, with very clear requirements, we can try to provide work-around. (Work-around, not FIX for your problem). I have bad news for you otherwise. – H.A.H. Aug 23 '23 at 10:00
  • This demo app can be used to experience the problem: https://github.com/alaskanrogue/KillUI This will provide further details and a procedure to do so: https://github.com/dotnet/maui/issues/16761 – Marc George Aug 25 '23 at 18:32

1 Answers1

0

Short answer is - you can not.

Years ago you could start real background services. I still have Kitkat device that runs one of those, without any problems, for years.

For a while now, you have to put a notification and run "foreground" service.

(Newer devices can dismiss this notification, then your service gets stopped. Older devices at least had the protection from closing.)

I will not go into details, but even the OS can kill non-system application, for whatever reason. (This happens when you let every manufacturer write his own interpretation of "good OS")

I advise you to consider the background and the foreground as separate processes. And arrange communication between them accordingly.

(Broadcast, notifications, etc.)

The truth is, that with every Android release this situation gets worse. And this requires continuous engineering effort to keep this organization working. So if you find a way to avoid it, before you have made it once, it will be even better.

H.A.H.
  • 2,104
  • 1
  • 8
  • 21