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

Support background tasks #358

Closed
ralfstx opened this issue Mar 25, 2015 · 18 comments
Closed

Support background tasks #358

ralfstx opened this issue Mar 25, 2015 · 18 comments
Assignees
Labels
Milestone

Comments

@ralfstx
Copy link
Member

ralfstx commented Mar 25, 2015

Currently, all JavaScript code is executed in the UI thread. This is fine for UI updates, but more complex operations will block the UI. We'll need to provide a way to run JS code in the background.

@ralfstx ralfstx added this to the 0.9.4 milestone Mar 25, 2015
@mpost
Copy link
Member

mpost commented Mar 25, 2015

The web has the service worker. Not sure if fully applicable to tabris.js but we should take a look. http://www.html5rocks.com/en/tutorials/service-worker/introduction/

@jonek
Copy link
Member

jonek commented Mar 25, 2015

JXcore is able to run JS on multiple V8 instance (multithreaded).
http://jxcore.com/docs/jxcore-feature-multithreading.html#jxcore_feature_multithreading_multithreading

Different threads communicate over message passing
process.sendToMain(param)
or by a tasks result when it is finished.

Could this also be used for Tabris.js?

@jordiboehme
Copy link
Contributor

On iOS, the JavaScript VM already runs on a different thread. But the UI thread has to wait, as we execute events synchronously.

@jonek
Copy link
Member

jonek commented Mar 25, 2015

As I understand it, a background task could never access the UI (thread executing the main JS instance) directly.

@bFlood
Copy link

bFlood commented Jul 31, 2015

I have not tried it yet but here is a cordova plugin that used JXCore, I'm guessing this would work in tabris-js
https://github.com/jxcore/jxcore-cordova

@sand123
Copy link

sand123 commented Jan 25, 2017

Hi, Tabris.js team! Any updates on this feature? On initial run, my app downloads ~ 5Mb JSON cache data, and everything is fine except system dialog - app doesn't respond - continue. Even though background task won't be able to interact with UI - event-based approach would be enough for intensive data transfer

@ralfstx
Copy link
Member Author

ralfstx commented Jan 25, 2017

Unfortunately, no updates yet. However, downloading is already asynchronous, what makes you UI block then? Is it the JSON parsing?

@sand123
Copy link

sand123 commented Jan 26, 2017

Yes, it does once but takes about 3 seconds to parse ~12000 records. Ok, I'll change JSON from assoc to numeric array and load in chunks of 1000 with visual progress bar.
Thanks for answer

@mpost
Copy link
Member

mpost commented Jan 26, 2017

If your storage requirements become more demanding you can also resort to a SQLite database via a plugin like: https://github.com/litehelpers/Cordova-sqlite-storage. This should speed up your load time significantly.

@ralfstx ralfstx added doc and removed doc labels May 17, 2017
@mpost mpost modified the milestones: 0.9.4, 3.0 Jun 14, 2018
@mpost mpost self-assigned this Jun 26, 2018
@mpost
Copy link
Member

mpost commented Sep 18, 2018

Closing as implemented.

@mpost mpost closed this as completed Sep 18, 2018
@jumpjack
Copy link

Any hint/tutorial/suggestions for a "background helloworld app"?

@cookieguru
Copy link
Contributor

@jumpjack #1594 (comment) still applies. If you're looking to create a background task from the UI (i.e. multithreading) see the Worker example

@jumpjack
Copy link

jumpjack commented Apr 28, 2022

Thanks, I was just trying to figure out if it is possible to write an app which constantly monitors, in background, a value provided by a server, and I think now it is.
But this raises another question: how to make the app warns the user upon specific value received from the server? Normally I should use an Android notification, but this would require an additional cordova plugin which I cannot test on developer app. Does it exist any other tabris-specific method to warn the user? I see I can change the color of the status bar, but can I also play a sound without loading a WAV file?

@cookieguru
Copy link
Contributor

cookieguru commented Apr 28, 2022

Like I mentioned above, you're not going to be able to keep the app running in the background to poll for a value

Instead, you should have the server push a notification with Firebase Cloud Messaging. You can use tabris-plugin-firebase for this

@jumpjack
Copy link

I don't understand: I wrote a test app which uses setInterval() to periodically update a counter, and it is working fine in background, even for some minutes, so I assume I can also do something else besides updating the counter, i.e. querying the server. (I don't know anything about firebase, I should start studying it from scratch).

@cookieguru
Copy link
Contributor

When an app goes into the background, it has a window of several minutes in which it is still allowed to create and use services

Source

Polling periodically will create a lot of network traffic. Not every user has an unlimited data plan. By switching to push instead of pull the user's device will only recieve the necessary data if and when it occurs.

@jumpjack
Copy link

jumpjack commented May 3, 2022

I am trying to study firabase, but it's very complicated, and I don't understand how it basically works: is it a server sending notification to my app? But if my tabris app in background is frozen, how can it receive messages? And if it is able to receive messages, then it should also be able to perform other tasks... or not? I am not an android developer, I'm just a javascript developer; I am trying to figure out if the plugin I need is "firebase" or "notification.local", or if I could just "beep" a sound manually when I need to alert the user, which I already successfully tested on my smartphone; together with changing color of status bar (aslo successfully tested), it would be enough for me.... but I need to be sure the app keeps running in background "for all the time I need", not just "for some minutes" ("some"? how many? What does it depend on?!?)

@cookieguru
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants