mob_background

Background execution keep-alive for Mob apps — keep the BEAM node running when the screen locks or the app is backgrounded.

Usage

# Keep the app alive when the screen locks (e.g. in mount/2):
MobBackground.keep_alive()

# Allow suspension again when no longer needed:
MobBackground.stop()

keep_alive/0 is idempotent — safe to call multiple times. status/0 reports, without changing anything, whether keep-alive can work in this host and whether it's on.

Run mix mob.selftest from a host app to check on a device that the native side is linked and wired up (MobBackground.SelfTest, a read-only background_status/0 call that never starts the keep-alive).

Install

# mix.exs
{:mob_background, "~> 0.1"}

# mob.exs
config :mob, :plugins, [:mob_background]
config :mob, :trusted_plugins, %{mob_background: "ed25519:<fingerprint>"}

mix mob.plugin.trust mob_background records the fingerprint, then mix mob.deploy --native.

Host requirements (the native build warns about these)

On Android the build adds everything when the plugin is activated: the FOREGROUND_SERVICE permissions, the BeamForegroundService class (copied into io/mob/background/ next to the bridge) and its <service android:foregroundServiceType="dataSync"> declaration. If you copied BeamForegroundService.kt into your app for plugin 0.1.x somewhere other than io/mob/background/, delete that copy.

The plugin deliberately doesn't add this one to your Info.plist (Apple rejects the mode in apps with no audio feature, so it's the app author's call); it prints as a warning on every mix mob.deploy --native of the host:

Notes

License

MIT.