Skip to content

android: go home instead of closing when back is pressed with no webview history - #249

Open
gabparrot wants to merge 1 commit into
nonbili:mainfrom
gabparrot:fix-back-press-home
Open

android: go home instead of closing when back is pressed with no webview history#249
gabparrot wants to merge 1 commit into
nonbili:mainfrom
gabparrot:fix-back-press-home

Conversation

@gabparrot

@gabparrot gabparrot commented Jun 27, 2026

Copy link
Copy Markdown

When the app was opened directly on a video (e.g. via a YouTube deep link, or via "Restore last playing on start" resuming a watch URL), there was no WebView back history to return to, so pressing the hardware back button called Activity.finish() and closed the app instead of landing on the home page (#250).

NouTubeView.goBack only had two outcomes: navigate back if canGoBack() is true, otherwise finish the activity. There was no path that landed the user on the home page first.

When canGoBack() is false, check the current path. If we're already on a home root (/ or empty), finish the activity as before so the user can still close the app from home. Otherwise navigate the WebView to the current host's root (e.g. https://m.youtube.com/ or https://music.youtube.com/) and clear the WebView history once the load completes (via a pendingClearHistory flag consumed in onPageFinished), so the next back press from home closes the app cleanly instead of bouncing back to the video.

canGoBack() paths, share-intent handling, and the "Restore last playing on start" setting are unchanged.

Closes #250

@gabparrot
gabparrot force-pushed the fix-back-press-home branch from 9b6630b to d575c79 Compare June 27, 2026 13:59
@gabparrot
gabparrot force-pushed the fix-back-press-home branch from d575c79 to 4feb286 Compare June 27, 2026 14:10
}

fun requestGoHome() {
val home = Uri.parse(webView.url ?: "").buildUpon()?.path("/")?.clearQuery()?.fragment(null)?.build()?.toString()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of depending on current url, should we map to either https://m.youtube.com/ or https://music.youtube.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Back button closes the app when opened directly on a video

2 participants