React-native: Execute post request after 20 seconds, even if app goes on backgound
When app runs in foreground, i execute successfully a POST-request using setTimeout with 20 seconds like this:
setTimeout(function() {
/*POST request is done here*/
}, 20000);
Though, if in meanwhile user places the app on background, by pressing home button for example, then my post won't get fired after 20 seconds.
On Android though, i checked that if 20 seconds get passed, and then i open the app(make it be in foreground), then post is executed immediately. (Haven't tested on ios to see if same thing happens). So i have the following questions:
1) Same behavior is happening on IOS side too?
2) Should i expect exactly same behavior if timeout had 15 mins timer and not 20 seconds?
3) How can i solve this problem? I need to contact to an endpoint after some time, and can't do it while app is in background with setTimeout.
Using libraries like react-native-background-task do not help in this situation, as i need to execute code after exactly 20 secs(or 10 mins etc) and not some time in future like 15 mins+
react-native background-process android-background ios-background-mode
add a comment |
When app runs in foreground, i execute successfully a POST-request using setTimeout with 20 seconds like this:
setTimeout(function() {
/*POST request is done here*/
}, 20000);
Though, if in meanwhile user places the app on background, by pressing home button for example, then my post won't get fired after 20 seconds.
On Android though, i checked that if 20 seconds get passed, and then i open the app(make it be in foreground), then post is executed immediately. (Haven't tested on ios to see if same thing happens). So i have the following questions:
1) Same behavior is happening on IOS side too?
2) Should i expect exactly same behavior if timeout had 15 mins timer and not 20 seconds?
3) How can i solve this problem? I need to contact to an endpoint after some time, and can't do it while app is in background with setTimeout.
Using libraries like react-native-background-task do not help in this situation, as i need to execute code after exactly 20 secs(or 10 mins etc) and not some time in future like 15 mins+
react-native background-process android-background ios-background-mode
add a comment |
When app runs in foreground, i execute successfully a POST-request using setTimeout with 20 seconds like this:
setTimeout(function() {
/*POST request is done here*/
}, 20000);
Though, if in meanwhile user places the app on background, by pressing home button for example, then my post won't get fired after 20 seconds.
On Android though, i checked that if 20 seconds get passed, and then i open the app(make it be in foreground), then post is executed immediately. (Haven't tested on ios to see if same thing happens). So i have the following questions:
1) Same behavior is happening on IOS side too?
2) Should i expect exactly same behavior if timeout had 15 mins timer and not 20 seconds?
3) How can i solve this problem? I need to contact to an endpoint after some time, and can't do it while app is in background with setTimeout.
Using libraries like react-native-background-task do not help in this situation, as i need to execute code after exactly 20 secs(or 10 mins etc) and not some time in future like 15 mins+
react-native background-process android-background ios-background-mode
When app runs in foreground, i execute successfully a POST-request using setTimeout with 20 seconds like this:
setTimeout(function() {
/*POST request is done here*/
}, 20000);
Though, if in meanwhile user places the app on background, by pressing home button for example, then my post won't get fired after 20 seconds.
On Android though, i checked that if 20 seconds get passed, and then i open the app(make it be in foreground), then post is executed immediately. (Haven't tested on ios to see if same thing happens). So i have the following questions:
1) Same behavior is happening on IOS side too?
2) Should i expect exactly same behavior if timeout had 15 mins timer and not 20 seconds?
3) How can i solve this problem? I need to contact to an endpoint after some time, and can't do it while app is in background with setTimeout.
Using libraries like react-native-background-task do not help in this situation, as i need to execute code after exactly 20 secs(or 10 mins etc) and not some time in future like 15 mins+
react-native background-process android-background ios-background-mode
react-native background-process android-background ios-background-mode
edited Nov 20 '18 at 13:37
angelos_lex
asked Nov 20 '18 at 13:31
angelos_lexangelos_lex
32519
32519
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
try this library it sets time what you want to set, but remember ios won't allow the time more than 30 sec
https://github.com/ocetnik/react-native-background-timer
Where is this max timeout limit specified? For example, an interval of 10 sec for 5 minutes is impossible?
– angelos_lex
Nov 20 '18 at 18:53
add a comment |
I've had same kind of problem, and I used react-native-background-timer and it worked perfectly for Android.
How long is the maximum timeout that i can set? Can i add timeout after 15 minutes? On both platforms? I can't find detailed information about it, any help highly appreciated!
– angelos_lex
Nov 20 '18 at 18:52
ios won't allow more than 30sec in background unless you are backed by native code
– Ammar Tariq
Nov 20 '18 at 20:02
for android you could add any timeout as long as app is running is background
– meta4
Nov 21 '18 at 9:24
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53394146%2freact-native-execute-post-request-after-20-seconds-even-if-app-goes-on-backgou%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
try this library it sets time what you want to set, but remember ios won't allow the time more than 30 sec
https://github.com/ocetnik/react-native-background-timer
Where is this max timeout limit specified? For example, an interval of 10 sec for 5 minutes is impossible?
– angelos_lex
Nov 20 '18 at 18:53
add a comment |
try this library it sets time what you want to set, but remember ios won't allow the time more than 30 sec
https://github.com/ocetnik/react-native-background-timer
Where is this max timeout limit specified? For example, an interval of 10 sec for 5 minutes is impossible?
– angelos_lex
Nov 20 '18 at 18:53
add a comment |
try this library it sets time what you want to set, but remember ios won't allow the time more than 30 sec
https://github.com/ocetnik/react-native-background-timer
try this library it sets time what you want to set, but remember ios won't allow the time more than 30 sec
https://github.com/ocetnik/react-native-background-timer
answered Nov 20 '18 at 13:57


Ammar TariqAmmar Tariq
979
979
Where is this max timeout limit specified? For example, an interval of 10 sec for 5 minutes is impossible?
– angelos_lex
Nov 20 '18 at 18:53
add a comment |
Where is this max timeout limit specified? For example, an interval of 10 sec for 5 minutes is impossible?
– angelos_lex
Nov 20 '18 at 18:53
Where is this max timeout limit specified? For example, an interval of 10 sec for 5 minutes is impossible?
– angelos_lex
Nov 20 '18 at 18:53
Where is this max timeout limit specified? For example, an interval of 10 sec for 5 minutes is impossible?
– angelos_lex
Nov 20 '18 at 18:53
add a comment |
I've had same kind of problem, and I used react-native-background-timer and it worked perfectly for Android.
How long is the maximum timeout that i can set? Can i add timeout after 15 minutes? On both platforms? I can't find detailed information about it, any help highly appreciated!
– angelos_lex
Nov 20 '18 at 18:52
ios won't allow more than 30sec in background unless you are backed by native code
– Ammar Tariq
Nov 20 '18 at 20:02
for android you could add any timeout as long as app is running is background
– meta4
Nov 21 '18 at 9:24
add a comment |
I've had same kind of problem, and I used react-native-background-timer and it worked perfectly for Android.
How long is the maximum timeout that i can set? Can i add timeout after 15 minutes? On both platforms? I can't find detailed information about it, any help highly appreciated!
– angelos_lex
Nov 20 '18 at 18:52
ios won't allow more than 30sec in background unless you are backed by native code
– Ammar Tariq
Nov 20 '18 at 20:02
for android you could add any timeout as long as app is running is background
– meta4
Nov 21 '18 at 9:24
add a comment |
I've had same kind of problem, and I used react-native-background-timer and it worked perfectly for Android.
I've had same kind of problem, and I used react-native-background-timer and it worked perfectly for Android.
answered Nov 20 '18 at 13:57
meta4meta4
366517
366517
How long is the maximum timeout that i can set? Can i add timeout after 15 minutes? On both platforms? I can't find detailed information about it, any help highly appreciated!
– angelos_lex
Nov 20 '18 at 18:52
ios won't allow more than 30sec in background unless you are backed by native code
– Ammar Tariq
Nov 20 '18 at 20:02
for android you could add any timeout as long as app is running is background
– meta4
Nov 21 '18 at 9:24
add a comment |
How long is the maximum timeout that i can set? Can i add timeout after 15 minutes? On both platforms? I can't find detailed information about it, any help highly appreciated!
– angelos_lex
Nov 20 '18 at 18:52
ios won't allow more than 30sec in background unless you are backed by native code
– Ammar Tariq
Nov 20 '18 at 20:02
for android you could add any timeout as long as app is running is background
– meta4
Nov 21 '18 at 9:24
How long is the maximum timeout that i can set? Can i add timeout after 15 minutes? On both platforms? I can't find detailed information about it, any help highly appreciated!
– angelos_lex
Nov 20 '18 at 18:52
How long is the maximum timeout that i can set? Can i add timeout after 15 minutes? On both platforms? I can't find detailed information about it, any help highly appreciated!
– angelos_lex
Nov 20 '18 at 18:52
ios won't allow more than 30sec in background unless you are backed by native code
– Ammar Tariq
Nov 20 '18 at 20:02
ios won't allow more than 30sec in background unless you are backed by native code
– Ammar Tariq
Nov 20 '18 at 20:02
for android you could add any timeout as long as app is running is background
– meta4
Nov 21 '18 at 9:24
for android you could add any timeout as long as app is running is background
– meta4
Nov 21 '18 at 9:24
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53394146%2freact-native-execute-post-request-after-20-seconds-even-if-app-goes-on-backgou%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown