MaikuB / MaikuB/flutter_local_notifications
NullPointerException when restarting the foreground service with a null intent
Nobody has claimed this yet.
- Dominant language
- Dart
- Stars
- 2.7k
- Forks
- 1.6k
- Avg merge
- 4d 8h
- Merged PRs (30d)
- 4
Description
I'm getting a Fatal Exception: java.lang.RuntimeException: Unable to start service com.dexterous.flutterlocalnotifications.ForegroundService@d50aeda with null: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.Serializable android.content.Intent.getSerializableExtra(java.lang.String, java.lang.Class)' on a null object reference
t seems to happen when the app is in the background and the user taps on the foregroundservice notification. I'm not able to reproduce it myself, caught by Crashlytics.
Using the default: 'START_STICKY', I would just need the tap on the foreground to open the app.
Current implementation:
Future<void> _startForegroundService(
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin,
int id,
String title,
String body,
AndroidNotificationDetails details,
) async {
try {
await flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.startForegroundService(
id,
title,
body,
notificationDetails: details,
// startType:
);
} catch (e) {
print('Error starting foreground service: $e');
}
}
@pragma('vm:entry-point')
static void notificationTapBackground(
NotificationResponse notificationResponse) {
// Handle background notification tap here
print(
'Notification tapped in background: ${notificationResponse.actionId}');
}
What am I missing here?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the Android implementation behind startForegroundService and trace how a null intent is handled when the foreground-service notification is tapped. Reproduce or inspect the reported Crashlytics failure, then verify that restarting with a null intent no longer throws and that the tap opens the app as intended.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, dart, flutter
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100