Rapsssito / react-native-background-actions

React Native background service library for running background tasks forever in Android & iOS.
MIT License
819 stars 117 forks source link

Is there any way to start the service on Android restart? #107

Closed dn32 closed 3 years ago

dn32 commented 3 years ago

Is there any way to start the service on Android restart? See what I tried without success:

public class StartMyServiceAtBootReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
        {
             context.startForegroundService(new Intent(context, com.asterinet.react.bgactions.RNBackgroundActionsTask.class));
        } 
        else 
        {
             context.startService(new Intent(context, com.asterinet.react.bgactions.RNBackgroundActionsTask.class));
        }
    }
}

Error:

FATAL EXCEPTION: main
Process: br.com.auvo.app, PID: 17388
java.lang.RuntimeException: Unable to start service com.asterinet.react.bgactions.RNBackgroundActionsTask@bae1d25 with Intent { cmp=br.com.auvo.app/com.asterinet.react.bgactions.RNBackgroundActionsTask }: java.lang.IllegalArgumentException: Extras cannot be null
    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4794)
    at android.app.ActivityThread.access$2000(ActivityThread.java:301)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2196)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:246)
    at android.app.ActivityThread.main(ActivityThread.java:8595)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Caused by: java.lang.IllegalArgumentException: Extras cannot be null
    at com.asterinet.react.bgactions.RNBackgroundActionsTask.onStartCommand(RNBackgroundActionsTask.java:80)
    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4776)
    ... 8 more
Rapsssito commented 3 years ago

@dn32, I am sorry, but I was not able to get it to work. Take a look at #43 for more info.

peterkimga commented 7 months ago

@Rapsssito

Hi. Is this still impossible to implement even now?

Regards