Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[android][ios][ts][docs][ncl] implement background fetch on Android #3281

Merged
merged 10 commits into from Jan 24, 2019

Conversation

@tsapeta
Copy link
Member

commented Jan 22, 2019

Why

Closes https://expo.canny.io/feature-requests/p/android-background-fetch-support

How

Android doesn't have its own background fetch feature, however I could easily imitate its behavior using AlarmManager with wakeup option.
I also had to change a few things in TaskManager, the most important one is the change in pending intents. Now, two pending intents created for the same task will be equal (see https://developer.android.com/reference/android/content/Intent#filterEquals(android.content.Intent)). Thanks to this, it's easier to cancel existing pending intents.

Test Plan

Tested against BackgroundFetch example in native-component-list

@tsapeta tsapeta added this to the SDK33 milestone Jan 22, 2019

@tsapeta tsapeta added the in progress label Jan 22, 2019

@tsapeta tsapeta force-pushed the @tsapeta/android-background-fetch branch from 359559e to 14fd128 Jan 22, 2019

@tsapeta tsapeta requested a review from sjchmiela Jan 22, 2019

@sjchmiela

This comment has been minimized.

Copy link
Contributor

commented Jan 22, 2019

Sorry, we no longer accept new features in Expo.

@sjchmiela sjchmiela closed this Jan 22, 2019

@sjchmiela sjchmiela removed the in progress label Jan 22, 2019

@sjchmiela

This comment has been minimized.

Copy link
Contributor

commented Jan 22, 2019

Just kidding! 🤣

@sjchmiela sjchmiela reopened this Jan 22, 2019

@sjchmiela
Copy link
Contributor

left a comment

Looks good to me, thanks! We could also try implementing starting service at the device's boot, couldn't we? I found this resource useful https://github.com/codepath/android_guides/wiki/Starting-Background-Services#using-with-alarmmanager-for-periodic-tasks

- **taskName (_string_)** -- Name of the task to register. The task needs to be defined first - see [TaskManager.defineTask](../task-manager/#taskmanagerdefinetasktaskname-task) for more details.
- **taskName (_string_)** -- Name of the task to register. The task needs to be defined first - see [TaskManager.defineTask](../task-manager#taskmanagerdefinetasktaskname-task) for more details.
- **options (_object_)** -- An object of options:
- **interval (_number_)** -- Inexact interval in seconds between subsequent repeats of the background fetch alarm. The final interval may differ from the specified one to minimize wakeups and battery usage. Defaults to **15 minutes**. (**Android only**, see [BackgroundFetch.setMinimumIntervalAsync](#backgroundfetchsetminimumintervalasyncminimuminterval) for iOS alternative)

This comment has been minimized.

Copy link
@sjchmiela

sjchmiela Jan 23, 2019

Contributor

Maybe on iOS we could call BackgroundFetch.setMinimumIntervalAsync behind the scenes when this option is provided? 🤔

Show resolved Hide resolved packages/expo-background-fetch/src/BackgroundFetch.ts Outdated
Show resolved Hide resolved packages/expo-background-fetch/src/BackgroundFetch.ts Outdated

sjchmiela and others added some commits Jan 23, 2019

Apply suggestions from code review
Co-Authored-By: tsapeta <tsapeta@users.noreply.github.com>
@sjchmiela
Copy link
Contributor

left a comment

LGTM, just two minor comments

sjchmiela and others added some commits Jan 24, 2019

code review suggestion
Co-Authored-By: tsapeta <tsapeta@users.noreply.github.com>

@tsapeta tsapeta merged commit 7af7d0b into master Jan 24, 2019

2 of 3 checks passed

client Workflow: client
Details
docs Workflow: docs
Details
sdk Workflow: sdk
Details

@tsapeta tsapeta deleted the @tsapeta/android-background-fetch branch Jan 24, 2019

@tsapeta tsapeta removed the in progress label Jan 24, 2019

- **minimumInterval (_number_)** -- Inexact interval in seconds between subsequent repeats of the background fetch alarm. The final interval may differ from the specified one to minimize wakeups and battery usage.
On Android it defaults to **15 minutes**. On iOS it calls [BackgroundFetch.setMinimumIntervalAsync](#backgroundfetchsetminimumintervalasyncminimuminterval) behind the scenes and the default value is the smallest fetch interval supported by the system (**10-15 minutes**).
- **stopOnTerminate (_boolean_)** -- Whether to stop receiving background fetch events after user terminates the app. Defaults to `true`. (**Android only**)
- **startOnBoot (_boolean_)** -- Whether to restart background fetch events when the device has finished booting. Defaults to `false`. (**Android only**)

This comment has been minimized.

Copy link
@BrodaNoel

BrodaNoel Mar 28, 2019

Contributor

Is there a way to add a bit more information about the stopOnTerminate?
What does exactly means "after user terminates the app"?

This comment has been minimized.

Copy link
@brentvatne

brentvatne Mar 28, 2019

Member

background app: switch to another
terminate app: close it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.