Introducing a new way to review your PRs.

Read the announcement

junkfood02 / seal

🦭 Video/Audio Downloader for Android, based on yt-dlp

View on GitHub

13 documents · Updated Nov 16, 2026

docs / app-entry-navigation-and-lifecycle

App Entry, Navigation, and Lifecycle

Overview

Android process startup is rooted in app/…/AndroidManifest.xml, which binds the application class to com.junkfood.seal.App and declares three activities that make up the app-level entry surface. MainActivity is the launcher and full app shell; QuickDownloadActivity is an exported share/link target shown as a dialog-style quick download surface; CrashReportActivity is internal-only and is launched by process initialization or the uncaught exception handler when startup/runtime initialization fails. The manifest also declares the app's foreground DownloadService, the FileProvider authority used for app-owned file URIs, the AppCompat locales metadata service, and NotificationActionReceiver.

app/…/App.kt performs process-wide initialization before any Compose screen is shown. It initializes MMKV, starts Koin with the singleton DownloaderV2 and top-level view models, stores static application context/package/system-service references, applies dynamic colors, and starts a supervisor applicationScope. On an IO coroutine it initializes YoutubeDL, FFmpeg, and Aria2c, writes cookie content from the database to the cookie file, and removes outdated APKs; failures in this async boot path call startCrashReportActivity(). The same crash report launcher is installed as Thread.setDefaultUncaughtExceptionHandler, and includes getVersionReport() output plus the stack trace in the error_report extra consumed by CrashReportActivity. App also owns the process-level service binding helpers startService()/stopService(), default audio/video/command directory state, and persisted directory updates.

app/…/MainActivity.kt is singleTask and handles launcher, ACTION_SEND text/plain, and ACTION_VIEW HTTP/HTTPS/media intents. On create it applies the stored locale on API levels below 33, enables edge-to-edge, updates App.context to the activity base context, and builds the root Compose tree: KoinContext -> window size calculation -> SettingsProvider -> SealTheme -> AppEntry. Because the activity is singleTask, later incoming share/view intents arrive in onNewIntent(), where getSharedURL() extracts either dataString or the first URL from shared text and posts DownloadDialogViewModel.Action.ShowSheet(listOf(url)) to the shared download dialog view model. The current onCreate() path does not consume the initial share/view intent; initial direct-link handling belongs to QuickDownloadActivity or to any future explicit handling added before AppEntry is composed.

app/…/QuickDownloadActivity.kt is a separate exported, singleInstance, dialog-themed entrypoint for share/link downloads. It extracts the shared URL during onCreate(), finishes immediately if none is found, binds the download service through App.startService(), makes its window transparent/fullscreen, applies locale compatibility, obtains the Koin DownloadDialogViewModel, and posts Action.ShowSheet(listOf(sharedUrlCached)). Its Compose content only hosts the download bottom sheet and secondary selection pages from the download configuration flow: when the sheet becomes hidden and the selection state is idle, the activity finishes; format and playlist selection dismissals reset the view model and finish the activity.

app/…/CrashReportActivity.kt is an internal Compose shell for fatal error display. It reads error_report, renders it in CrashReportPage, and offers a single copy-and-exit action that copies the full report and calls finishAffinity(). onDestroy() also calls finishAffinity() when the activity is finishing, so crash reports terminate the task rather than returning to the failing shell.

The main app UI is composed by app/…/AppEntry.kt. It creates the NavController, drawer state, CookiesViewModel, a lifecycle-safe onNavigateBack, and a NavHost starting at Route.HOME. Top-level destinations are Route.HOME, Route.TASK_LIST, Route.SETTINGS_PAGE, and Route.DOWNLOADS; currentTopDestination tracks the last top-level route so expanded layouts can keep the navigation rail selection stable while nested settings/detail pages are active. If the shared DownloadDialogViewModel enters SheetState.Configure, AppEntry forces the nav stack back to Route.HOME before showing the download configuration surface.

AppEntry hands major flows to their owning pages rather than implementing them inline: Route.HOME hosts DownloadPageV2, Route.DOWNLOADS hosts VideoListPage, Route.TASK_LIST hosts TaskListPage, and Route.TASK_LOG/{task_hashcode} hosts TaskLogPage. The nested settingsGraph() defines the settings routes and handoffs, including general/download-format/directory/appearance/interaction/language/template/network/cookie/troubleshooting/about/update/sponsor/credits pages. WebViewPage flushes CookieManager after navigating back so generated cookies survive leaving the embedded browser.

app/…/NavigationDrawer.kt adapts the navigation shell by window width. Compact and medium widths use only a ModalNavigationDrawer; expanded width adds a persistent 92dp rail with menu, downloads history, custom command, and settings icons while still using a modal sheet for the full drawer. Drawer items close the sheet first and then call onNavigateToRoute(), while AppEntry performs the actual navController.navigate() with launchSingleTop and popUpTo(Route.HOME) for drawer-driven route changes. Quick settings entries in the drawer jump directly to common settings graph destinations such as general preferences, download directory, cookie profile, troubleshooting, and about.

App-level dialogs and update surfaces are attached to the app shell. app/…/AppEntry.kt always composes AppUpdater() and YtdlpUpdater() beside the NavHost, so update prompts can appear regardless of the current route. app/…/AppUpdater.kt checks auto-update eligibility once on composition using PreferenceUtil.isNetworkAvailableForDownload() and PreferenceUtil.isAutoUpdateEnabled(), then calls UpdateUtil.checkForUpdate() on IO. When a release is available, it shows UpdateDialogImpl, downloads the APK with progress, requests REQUEST_INSTALL_PACKAGES, and falls back to the unknown-app-sources settings screen when needed before installing. app/…/UpdateDialog.kt also exposes UpdateDialog() for a release-driven update prompt used from manual update surfaces; unlike AppUpdater, it directly calls UpdateUtil.installLatestApk() after download completion on Android M and above. app/…/WelcomeDialog.kt is a reusable first-run/user-guide dialog keyed by the WELCOME_DIALOG preference; dismissal increments or disables the counter, and confirmation delegates navigation to the caller, normally to settings.

Routing guidance for this area: add new manifest entrypoints in AndroidManifest.xml and give each one a small lifecycle shell like MainActivity, QuickDownloadActivity, or CrashReportActivity that only parses intents, applies process/UI wrappers, and hands off to composables or view models. Add new in-app destinations to Route.kt, register them in AppEntry.kt or settingsGraph() depending on whether they are top-level or settings-scoped, and expose drawer/rail entry points in NavigationDrawer.kt only when the destination is a durable app-level navigation target. Keep download-dialog launches routed through DownloadDialogViewModel so AppEntry can enforce the Route.HOME handoff before configuration UI appears.

Coupling

  • If an exported intent filter changes in app/…/AndroidManifest.xml, update URL/text extraction in the matching lifecycle shell: MainActivity.getSharedURL() handles later singleTask intents, while QuickDownloadActivity.getSharedURL() handles its initial singleInstance quick-download intent. A manifest action or MIME change without parser support will silently open the app without showing a download sheet.
  • If DownloadDialogViewModel.SheetState.Configure or the download sheet state model changes, verify AppEntry.kt and QuickDownloadActivity.kt together. AppEntry uses this state to pop back to Route.HOME, while QuickDownloadActivity uses sheet/selection state to decide when to finish the dialog activity.
  • If route constants or argument names in Route.kt change, update both AppEntry.kt and NavigationDrawer.kt. AppEntry owns the NavHost registrations and TopDestinations; the drawer and expanded rail compare raw route strings to mark selection and perform navigation.
  • If update installation behavior changes in UpdateUtil, check both AppUpdater.kt and UpdateDialog.kt. Automatic shell updates request install permission and may launch unknown-app-source settings; the manual dialog path starts installation directly after download completion on supported API levels.
  • If process-level initialization in App.kt starts depending on an Activity context, keep it out of Application.onCreate() or guard it carefully. App.kt runs before MainActivity replaces App.context with its base context, and startup failures route through CrashReportActivity.

Risks

  • app/…/MainActivity.kt only handles shared/view URLs in onNewIntent(). Because onCreate() ignores the launch intent, opening MainActivity fresh through its ACTION_SEND or ACTION_VIEW manifest filters can fail to show the download sheet unless the intent is delivered to an existing singleTask instance; route new initial-intent behavior explicitly if those filters remain on MainActivity.
  • app/…/App.kt starts CrashReportActivity from both async library initialization failures and the default uncaught exception handler. If crash reporting itself throws or initialization fails repeatedly, the app can loop into the crash UI before the main shell is usable.
  • app/…/AppUpdater.kt stores updateJob as a plain local variable inside a composable. Recomposition can reset that reference, so dismissing the update dialog may not cancel an already-started download job if the composable recomposed after the job was assigned.