Skip to content

improved app startup and handled user notification#20486

Closed
rudrat0319 wants to merge 1 commit intoankidroid:mainfrom
rudrat0319:fix/improve-app-startup
Closed

improved app startup and handled user notification#20486
rudrat0319 wants to merge 1 commit intoankidroid:mainfrom
rudrat0319:fix/improve-app-startup

Conversation

@rudrat0319
Copy link

Purpose / Description

Closes: #20168
Parent issue: #19552

When a component fails to initialize during app startup, the failure was previously silent. The app would continue loading but the affected feature would be unavailable with no notification to the user or developer.

The specific case that motivated this change is the ReviewReminder deserialization failure (#20163), where a missing onlyNotifyIfNoReviews field caused AlarmManagerService.scheduleAllNotifications() to fail silently.

Changes

AnkiDroidApp.kt

  • Added NonFatalInitializationError data class to represent a
    recoverable startup failure, holding the component name and exception
  • Added nonFatalStartupErrors list to collect failures during onCreate()
  • Wrapped AlarmManagerService.scheduleAllNotifications() in a
    try-catch block so a ReviewReminder deserialization failure no longer
    silently breaks the notification system
  • Exposed nonFatalStartupErrors via companion object for DeckPicker
    to read after startup completes

DeckPicker.kt

  • Added showNonFatalStartupErrors() function called at the end of
    onCreate(), after the UI is fully ready
  • Shows an AlertDialog listing which components failed to load
  • Reports each error to developers via CrashReportService/ACRA so
    failures are tracked even when users don't report them

res/values/strings.xml

  • Added startup_error_title string
  • Added startup_error_message string

Behavior

Before this change:

  • AlarmManagerService fails during startup
  • App continues silently
  • Review reminders don't work
  • User has no idea why
  • Developer gets no report

After this change:

  • AlarmManagerService fails during startup
  • Error is caught and collected
  • App continues loading remaining components
  • User sees a dialog listing which features failed
  • Developer receives an automatic crash report via ACRA

Testing

  • Tested on API 33 emulator (Pixel 6)
  • Verified dialog appears when a startup component throws
  • Verified dialog does NOT appear on a clean startup with no errors
  • Verified ACRA report is sent for each captured error

…p will notify users as I've wrapped AlarmManagerService call in try-catch in AnkiDroidApp.kt
@github-actions
Copy link
Contributor

Important

Maintainers: This PR contains Strings changes

  1. Sync Translations before merging this PR and wait for the action to complete
  2. Review and merge the auto-generated PR in order to sync all user-submitted translations
  3. Sync Translations again and merge the PR so the huge automated string changes caused by merging this PR are by themselves and easy to review

@david-allison
Copy link
Member

Initially: investigate https://developer.android.com/jetpack/androidx/releases/startup

-- #20168 (comment)

This PR isn't close to what was expected. Sorry.

@rudrat0319
Copy link
Author

@david-allison I understand I might have mistaken or misunderstood what was supposed to be implemented. If you can help me understand better I can fix it and submit another PR. else, no issues.

@david-allison
Copy link
Member

No worries, I'll take it on when I have time

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve startup process & notifying users of nonfatal component errors

2 participants