Skip to content

Foreground service freezes when app dismissed #1078

@jektvik

Description

@jektvik

Have tried about just about every config concievable to get the foreground service running but it just won't continue executing as soon as I dismiss the parent app to the background.

await notifee.registerForegroundService((notification: Notification) => {
    return new Promise(resolve => {
      const interval2 = setInterval(() => console.log('testmessage'), 6000);

      notifee.onBackgroundEvent(async event => {
        if (event.type === EventType.DISMISSED) {

          await notifee.cancelNotification(notification.id || '');
          console.log('Handled DISMISSED onBackgroundEvent');
        }

        return resolve();
      });

      notifee.onForegroundEvent(async event => {
        if (event.type === EventType.DISMISSED) {
          await notifee.cancelNotification(notification.id || '');
        }

        return resolve();
      });
    });
  });
```

The above 'test message' will continue displaying every 6 s as long as the app is on the foreground but as soon as I return to main screen that execution freezes (i.e. it's not properly attached to the foreground service). When I open the app again, it may unfreeze.
The testmessage code is meant to actually be a 'refreshNotification' type of function, but it never worked therefore I'm attaching this simplified example.

Android logs keep spamming
`08-08 10:55:06.711   583   818 W IPCThreadState: Sending oneway calls to frozen process.`

Which I think may be indicative of what the issue is, i.e. the setInterval function isn't properly attached to any process (foregroundProcess?) which is meant to stay alive when the app is in the background.

Similarly, functions like

  await notifee.stopForegroundService();
  await notifee.cancelAllNotifications();
  
  seem to have no effect, i.e. even after I call them, the interval messages will keep executing if they'd been started like above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Keep Openthis label avoids the stale bot

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions