public interface BackgroundFetch
Background fetch is a mechanism whereby an application is granted permission by the operating system
to update its data periodically. At times of the native platform's choosing, an app that supports background
fetch will be started up (in the background), and its performBackgroundFetch(long, com.codename1.util.Callback)
method will be called.
Note: Since the app will be launched directly to the background, you cannot assume that the start()
method has been
run prior to the performBackgroundFetch(long, com.codename1.util.Callback)
method being called.
Apps that wish to implement background fetch must implement the BackgroundFetch
interface
in their main class. On iOS, you also need to include fetch
in the list of background
modes (i.e. include "fetch" in the ios.background_modes
build hint.)
In addition to implementing the BackgroundFetch
interface, apps must explicitly set the background fetch interval
calling Display.setPreferredBackgroundFetchInterval(int)
at some point, usually in the start()
or init()
method.
Currently background fetch is supported on iOS, Android, and in the Simulator (simulated using timers when the app is paused). You should
use the Display.isBackgroundFetchSupported()
method to find out if the current platform supports it.
Modifier and Type | Method and Description |
---|---|
void |
performBackgroundFetch(long deadline,
Callback<Boolean> onComplete)
A callback that may be periodically called by the platform to allow the app to
fetch data in the background.
|
void performBackgroundFetch(long deadline, Callback<Boolean> onComplete)
deadline
- The deadline (milliseconds since epoch) by which the fetch should be completed. If not completed by this time, the app may be killed by the OS. On iOS, there is a limit of 30 seconds to perform background fetches.onComplete
- Callback that MUST be called when the fetch is complete. If it is not called, some platforms (e.g. iOS) may refuse to allow the app to perform background fetches in the future.com.codename1.ui.Display.setPreferredBackgroundFetchInterval(int)
,
com.codename1.ui.Display.getPreferredBackgroundFetchInterval()
,
com.codename1.ui.Display.isBackgroundFetchSupported()