Skip to content

Too many registered receivers, total of 1000, causes the application to crash #373

@qoeru

Description

@qoeru

Hello!
We are using the package in flutter android app for sending big amounts of data.

Our analytics service reports periodic crash among users which we cannot reproduce:

java.lang.RuntimeException: Unable to create service com.pravera.flutter_foreground_task.service.ForegroundService: java.lang.IllegalStateException: Too many receivers, total of 1000, registered for pid: 9409, callerPackage: com.nda.nda
at android.app.ActivityThread.handleCreateService(ActivityThread.java:4298)
at android.app.ActivityThread.access$1500(ActivityThread.java:260)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1974)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7977)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:603)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:948)
Caused by: java.lang.IllegalStateException: Too many receivers, total of 1000, registered for pid: 9409, callerPackage: com.nda.nda
at android.os.Parcel.createExceptionOrNull(Parcel.java:2381)
at android.os.Parcel.createException(Parcel.java:2357)
at android.os.Parcel.readException(Parcel.java:2340)
at android.os.Parcel.readException(Parcel.java:2282)
at android.app.IActivityManager$Stub$Proxy.registerReceiverWithFeature(IActivityManager.java:5520)
at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1626)
at android.app.ContextImpl.registerReceiver(ContextImpl.java:1580)
at android.app.ContextImpl.registerReceiver(ContextImpl.java:1568)
at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:668)
at com.pravera.flutter_foreground_task.service.ForegroundService.q(Unknown Source)
at com.pravera.flutter_foreground_task.service.ForegroundService.onCreate(Unknown Source)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:4286)
... 8 more
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.am.ActivityManagerService.registerReceiverWithFeature(ActivityManagerService.java:15934)
at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2201)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2930)
at android.os.Binder.execTransactInternal(Binder.java:1154)
at android.os.Binder.execTransact(Binder.java:1123)

Here’s the configuration:

<service 
      android:name="com.pravera.flutter_foreground_task.service.ForegroundService"
      android:foregroundServiceType="dataSync"
      android:exported="false" />

And our foreground service code:

  bool _isInitialized = false;

  void init() {
    if (_isInitialized) return;

    FlutterForegroundTask.init(
      androidNotificationOptions: AndroidNotificationOptions(
        channelId: 'foreground_service',
        channelName: 'Channel name',
        channelDescription: 'Channel description',
        onlyAlertOnce: true,
        channelImportance: NotificationChannelImportance.DEFAULT,
      ),
      iosNotificationOptions: const IOSNotificationOptions(
        showNotification: false,
      ),
      foregroundTaskOptions: ForegroundTaskOptions(
        eventAction: ForegroundTaskEventAction.once(),
        autoRunOnBoot: true,
        allowWifiLock: true,
      ),
    );
    FlutterForegroundTask.addTaskDataCallback(taskDataCallback);

    _isInitialized = true;
  }

  Future<void> startService() async {
    final isRunning = await FlutterForegroundTask.isRunningService;
    if (isRunning) return;

    await FlutterForegroundTask.startService(
      serviceId: 1000,
      notificationTitle: 'Notification Title',
      notificationText: 'Notification Text',
      callback: startCallback,
    );
  }

  Future<void> stopService() async {
    await FlutterForegroundTask.stopService();
  }

Our current flutter_foreground_task version is 9.1.0, but the problem was detected on earlier (8.17.0) version as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions