Skip to content

Commit

Permalink
fix: Fix IllegalStateException "Not allowed to start service Intent"
Browse files Browse the repository at this point in the history
Co-authored-by: Jean-François Puissant <jean-francois.puissant@fleetback.com>
  • Loading branch information
drash-course and Jean-François Puissant authored Jun 30, 2021
1 parent d7d0f8d commit 1ba26c7
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,20 @@ public String getName() {
@SuppressWarnings("unused")
@ReactMethod
public void start(@NonNull final ReadableMap options, @NonNull final Promise promise) {
// Stop any other intent
if (currentServiceIntent != null) reactContext.stopService(currentServiceIntent);
// Create the service
currentServiceIntent = new Intent(reactContext, RNBackgroundActionsTask.class);
// Get the task info from the options
try {
// Stop any other intent
if (currentServiceIntent != null) reactContext.stopService(currentServiceIntent);
// Create the service
currentServiceIntent = new Intent(reactContext, RNBackgroundActionsTask.class);
// Get the task info from the options
final BackgroundTaskOptions bgOptions = new BackgroundTaskOptions(reactContext, options);
currentServiceIntent.putExtras(bgOptions.getExtras());
// Start the task
reactContext.startService(currentServiceIntent);
promise.resolve(null);
} catch (Exception e) {
promise.reject(e);
return;
}
// Start the task
reactContext.startService(currentServiceIntent);
promise.resolve(null);
}

@SuppressWarnings("unused")
Expand Down

0 comments on commit 1ba26c7

Please sign in to comment.