JulianAssmann / flutter_background

A flutter plugin to keep apps running in the background via foreground services. Android only.
https://pub.dev/packages/flutter_background
MIT License
86 stars 46 forks source link

Clarify what happens to the Dart VM #17

Open Timmmm opened 3 years ago

Timmmm commented 3 years ago

Great project. Was very easy to integrate into my app. The only think I'm unsure about is exactly how it affects app behaviour. As I understand it, without doing anything on Android your app can just be killed at any point, including when the phone is idle, when it's low on memory, or when the user swipes the app away.

If I enable background execution what exactly happens? It seems like you don't get any additional processes / isolates. I guess it just signals Android not to kill the app in more circumstances (but not all?).

Basically I'd really like a comment like this:

By default, Android will kill all apps in response to certain events:

  1. The system is low on memory and the app is not in the foreground.
  2. When the user swipes it away.
  3. ???

It will also suspend the entire system and therefore pause execution of apps under these circumstances:

  1. ???

When you enable background execution using this library it affects Android's killing/suspend behaviour in the following ways:

  1. It acquires a wakelock (does it?), so the system never sleeps. This affects battery life which is why a permission dialog is shown to disable battery optimisations.
  2. It creates a "foreground service" (which requires a notification to be shown). This prevents Android from killing the app when the system is low on memory, but it will still be killed if the user swipes it away.

(I have no idea how much of that is true, hence why it would be great to document it thoroughly!)

Thanks for the project anyway - it's very easy to use!