Skip to content

Lifecycle events and HeadlessJS on Android #15960

@vjeranc

Description

@vjeranc

I'm interested in how exactly lifecycle events work with HeadlessJS and how they should be used by react-native modules.

Example: If I were to make a background task where I'm fetching messages only over WiFi, I'd need NetInfo to tell me the network type. I'd register a listener and stop fetching if network provider changed.

The problem is that onHostResume, onHostDestroy and onHostPause listeners are triggered when something happens with the main activity.

In the above case, NetInfo unregisters receiver and the background task that can still be running (despite activity being destroyed or on pause) will no longer receive events on network provider. There might be other ways to solve the task above but there can be plenty of similar tasks that are crippled by things done in native when actions on activity trigger lifecycle changes.

There seem to be other non-react-native modules doing similar things and completely crippling the background task.

Is this expected behavior?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions