Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native: run javascript module from BroadcastReceiver

I'm trying to run javascript module twice a day in background, even if app is closed. I use BroadcastReceiver on Java side, but I don't know how to run javascript from onReceive() method without showing react View. I found one solution that run all application, but I'm looking for something like workers/service that will works in background.

public void onReceive(Context context, Intent intent) {
    String pn = context.getApplicationContext().getPackageName();
    Intent li = context.getPackageManager().getLaunchIntentForPackage(pn);
    context.startActivity(li);
}
like image 776
jonzee Avatar asked Sep 18 '25 06:09

jonzee


1 Answers

React Native 0.36 introduced Headless JS as a way to run tasks in JavaScript while your app is in the background.

You should take a look at this document.

like image 146
Octopitus Avatar answered Sep 20 '25 20:09

Octopitus