fix(android): catch ForegroundServiceStartNotAllowedException in back…#311
fix(android): catch ForegroundServiceStartNotAllowedException in back…#311dishit-wednesday wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
There was a problem hiding this comment.
Code Review
This pull request wraps the service start logic in a try-catch block to handle background start restrictions on Android 12+. The review feedback suggests catching IllegalStateException instead of a generic Exception to ensure that unrelated runtime errors, such as missing permissions, are not suppressed.
| } else { | ||
| context.startService(intent) | ||
| } | ||
| } catch (e: Exception) { |
There was a problem hiding this comment.
Catching a generic Exception is overly broad and can swallow unrelated runtime errors (such as SecurityException if the FOREGROUND_SERVICE permission is missing) that should be surfaced during development. Since the primary goal is to handle background start restrictions, catching IllegalStateException is more appropriate. On Android 12+ (API 31), ForegroundServiceStartNotAllowedException inherits from IllegalStateException, so this change will correctly handle the intended case while allowing other critical exceptions to be identified.
| } catch (e: Exception) { | |
| } catch (e: IllegalStateException) { |
Co-authored-by: Dishit <hanmadishit74@gmail.com>
|



…ground
Summary
Type of Change
Screenshots / Screen Recordings
Android
iOS
Checklist
General
Testing
npm test)React Native Specific
project.pbxproj)SPACING/TYPOGRAPHYconstants from the themeuseThemedStylespattern (not inline or staticStyleSheet.create)FlatList/FlashList(not.map()insideScrollView)Performance & Models
/vs\\)Security
Related Issues
Additional Notes