Correct how the app ends up with no Activity

The previous commit's comment and test said Android starts the app in the
background (a home-widget update, a notification-listener rebind) with
the glasses session running. A background start alone doesn't connect
the glasses; only the main page does. The state that breaks voice is
the Activity being destroyed afterwards: swiping the app away in Recents
destroys it while the foreground service keeps the process and session
running, and NativeScript then clears both foregroundActivity and
startActivity. On Android 12+ Back on the main page only moves the task
to the back, so the Activity survives it. Comment and test wording only.
This commit is contained in:
Om Alve committed 2026-11-02 13:28:21 +05:30
1 parent 9fac7a29ba
commit bdf4fc2f1d
2 files changed
+9 -8

No files matched your search

+4 -4
View File
@@ -69,10 +69,10 @@ async function ensurePermissions(
if (missing.length === 0) return; if (missing.length === 0) return;
// Only a request needs an Activity. Checking must not: Android can start // Only a request needs an Activity. Checking must not: the glasses session
// the app in the background (a home-widget update, a notification-listener // outlives it (swiping the app away in Recents destroys the Activity while
// rebind) with none, and the glasses session and voice input run from // the foreground service keeps the process running), and voice input
// there until the app is opened. // checks the microphone permission on every start.
const activity = getActivity(); const activity = getActivity();
await new Promise<void>((resolve, reject) => { await new Promise<void>((resolve, reject) => {
+5 -4
View File
@@ -8,9 +8,10 @@ const RECORD_AUDIO = 'android.permission.RECORD_AUDIO';
/** /**
* app/g2/android-permissions.ts against a stubbed Android: `granted` is the set * app/g2/android-permissions.ts against a stubbed Android: `granted` is the set
* of permissions already held, `activity` the foreground/start Activity (null * of permissions already held, `activity` the foreground/start Activity. It is
* when Android started the process in the background, e.g. for a home-widget * null once the app's Activity is destroyed (swiped away in Recents) while the
* update, and the app has not been opened yet). * foreground service keeps the process and the glasses session running:
* NativeScript then clears both foregroundActivity and startActivity.
*/ */
function permissions({ granted = [], activity = null } = {}) { function permissions({ granted = [], activity = null } = {}) {
const held = new Set(granted); const held = new Set(granted);
@@ -45,7 +46,7 @@ function permissions({ granted = [], activity = null } = {}) {
return { api: load('app/g2/android-permissions.ts'), requests }; return { api: load('app/g2/android-permissions.ts'), requests };
} }
test('a granted permission needs no Activity, so voice works after a background start', async () => { test('a granted permission needs no Activity, so voice works after the app is swiped away', async () => {
const { api, requests } = permissions({ granted: [RECORD_AUDIO], activity: null }); const { api, requests } = permissions({ granted: [RECORD_AUDIO], activity: null });
await api.ensureVoicePermissions(); await api.ensureVoicePermissions();
assert.equal(requests.length, 0); assert.equal(requests.length, 0);