diff --git a/app/(tabs)/_layout.tsx b/app/(tabs)/_layout.tsx index 2e64065..c36e1c9 100644 --- a/app/(tabs)/_layout.tsx +++ b/app/(tabs)/_layout.tsx @@ -238,19 +238,27 @@ export default function TabLayout() { // Handle app state changes (background/foreground) useEffect(() => { const handleAppStateChange = (nextAppState: AppStateStatus) => { - if (nextAppState === 'active' && sessionActiveRef.current) { - setTimeout(() => { - if (sessionActiveRef.current && !sttIsListening && status !== 'processing' && status !== 'speaking') { - console.log('[TabLayout] App foregrounded - restarting STT'); - safeStartSTT(); - } - }, 500); + // When app goes to background/inactive - stop voice session + // STT/TTS cannot work in background, so it's pointless to keep session active + if ((nextAppState === 'background' || nextAppState === 'inactive') && sessionActiveRef.current) { + console.log('[TabLayout] App going to background - stopping voice session'); + stopListening(); + stopSession(); + sessionActiveRef.current = false; + shouldRestartSTTRef.current = false; + pendingInterruptTranscriptRef.current = null; + } + + // When app comes back to foreground - do NOT auto-restart session + // User must manually press FAB to start new session + if (nextAppState === 'active') { + console.log('[TabLayout] App foregrounded - session remains stopped (user must restart via FAB)'); } }; const subscription = AppState.addEventListener('change', handleAppStateChange); return () => subscription.remove(); - }, [sttIsListening, status, safeStartSTT]); + }, [stopListening, stopSession]); // Handle voice FAB press - toggle listening mode // Must check ALL active states (listening, processing, speaking), not just isListening