The close button called stopService() and then app.exit(0) immediately.
stopService() is asynchronous — it posts to ActivityManager and onDestroy
runs later on the main thread — so the process often died mid-flight.
Android saw a foreground service whose process had died and, per
onStartCommand returning START_STICKY, restarted it. Whether the clean
path won was pure timing, which is why this worked when v0.7.3 shipped
and stopped working under v0.8's heavier startup and shutdown.
Nothing in gen/android had changed since v0.7.3 (verified: the diff is
empty) — this was a latent race, not a regression.
Fix, in two layers:
- NodeService persists a user_quit flag to SharedPreferences (commit(),
not apply(), since the process may die moments later). stopFromNative
sets it BEFORE calling stopService. onStartCommand treats a null intent
as "Android resurrected me" and, if the flag is set, calls
stopForeground(STOP_FOREGROUND_REMOVE) + stopSelf() and returns
START_NOT_STICKY. MainActivity clears the flag on genuine launch, so a
system-initiated kill still resumes via START_STICKY — the case that
behaviour exists for.
- exit_app awaits 400ms between the stop and app.exit(0) so the clean
path usually wins; the persisted flag is the backstop when it doesn't.
Not rebuilt — batching for 0.8.1.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LGiPD2cF75mnvneSCjdDC5