MaikuB / MaikuB/flutter_local_notifications

NullPointerException when restarting the foreground service with a null intent

Open
#2,298 6 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.