WorkManager vs JobScheduler - android-jobscheduler

In case I can use either WorkManager or JobScheduler, is there any preference in using JobScheduler? Are there options in JobScheduler that are not available in WorkManager?
Is JobScheduler going to deprecate in future Android versions?

Workmanager internally uses AlarmManger, Jobscheduler or Firebase Job Dispatcher based on Android API level so I don't think Jobscheduler will get deprecated.
Workmanger handles all scenario for you and also has easy to use API but beware that right now its in alpha stage so you may end up with some issues.

Related

Flutter: Executing a Task after App is Killed

I would like to execute some asynchronous code just before my Flutter App is killed by the OS due to low memory.
I am currently using the WidgetsBindingObserver mixin to listen to app lifecycle changes, and when the app is paused (before it is detached) start the code execution.
The code I'm trying to execute:
I am trying to commit something to a local cache using SharedPreferences, but to no avail. It doesn't end up committing the data.
The Potential Issues:
I'm not sure if it is primarily due to running code while the app is being detached - in which case it could be solved by using the WorkManager package.
Or, if it is related to accessing Shared Preferences after the app has already been detached.
Any help or insight would be welcome!
Unfortunately, using the WidgetsBindingObserver mixin doesn't work for my use-case. When the lifecycle status changes to detached, any asynchronous code executed after this is not able to complete in time.
I solved the problem using a local key-pair store called Hive to locally save the form data as it was inputted by the user. Then, when they are ready to resume the form completion, re-populate the form and allow them to continue filling it out.

Flutter & Dart : What is an isolate in flutter?

As I study about flutter, I notices that there is a thing called isolate.
What is it for? And how do we implement that? Can you give me a simple example?
Thank you in advance.
Isolate in flutter, similar with threading.
"Flutter is single-threaded but it is capable of doing multi-threading
stuff using Isolates (many processes). When Dart starts, there will be
one main Isolate(Thread). This is the main executing thread of the
application, also referred to as the UI Thread. In simple Flutter apps
you will only ever use one Isolate, and your app will run smoothly.
Isolates are:
Dart’s version of Threads. Do not share memory between each other.
Uses Ports and Messages to communicate between them. May use another
processor core if available. Runs code in parallel."
Docs & Simple Example
"Concurrent programming using isolates: independent workers that are
similar to threads but don't share memory, communicating only via
messages."
Official Docs

Observable.interval not working when the app is in the background

Using rxjava2 (2.1.8) Observable.interval to invoke a RESTful API every 13 minutes. Its working fine if the app is running in the foreground and not working when the app is in the background. I am unable to post the entire code code due to restrictions.
Observable.interval(13, TimeUnit.Milliseconds)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(...
Really appreciate your suggestions
For long running operation your code should be executed in a Service. There are though some limitations, introduced with Android 8, that you may want to check.
However, you can schedule your task using an AmarmManager or a better alternative: [JobScheduler][2]. With the JobScheduler you can also define the criteria that need to be met for executing your tasks.
NOTE:
.interval(13, TimeUnit.Milliseconds) means one item emitted every 13 milliseconds, not minutes!

What is blackberry's equivalent to Androids Looper?

Android has Looper, and iPhone has Run Loops. It seems like Blackberry would have a similar backed in facility to queue and run threads.
Does anyone know if there is?
I'm not too familiar with Android yet, but some quick reading shows that what you're looking for is the invoke series:
Application.invokeLater - this allows you to add a Runnable to the event queue of the main thread, optionally at a scheduled delay /repeat interval
Application.invokeAndWait - add the Runnable to the event queue of the main thread and wait for it to complete execution.
Application.cancelInvokeLater- cancel a scheduled invokeLater request.
Reference: http://www.blackberry.com/developers/docs/4.1api/net/rim/device/api/system/Application.html#invokeLater%28java.lang.Runnable%29
And: http://www.blackberry.com/developers/docs/4.1api/net/rim/device/api/ui/UiApplication.html

Threading in GWT (Client)

From what I understand, the entire client side of a GWT application is converted to Javascript when you build, therefore I suppose this question is related to both Javascript and the possibilities that GWT offers.
I have a couple of dozen processes that will need to be initiated in my GWT application, each process will then continuously make calls to a server. Does GWT support threading? Does the GWT client side support threading?
EDIT:
This link states:
No JavaScript knowledge required If you’re just a user of the framework,
which I am for the matter of discussion, you do not need to know JavaScript
in order to write dynamic content, be it client-side such as rolling frames,
docking panels or scheduled “multi-threading” tasks, or server-side calls
using XMLHttpRequests (aka AJAX).
or scheduled “multi-threading” tasks, what does this mean?
JavaScript doesn't support multithreading. However, GWT has a class to 'simulate' threading, which is not real multithreading, but in most cases does what you need: com.google.gwt.core.client.Scheduler.ScheduledCommand. The technique is based on the timer class, which executes a method after the given time elapses.
For example, when placing the following code in you own code, the scheduleDeferred method will return directly and your code continues after the command, while the execute() method is executed using the timer:
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
public void execute() {
.. code here is executed using the timer technique.
}
});
You can create a repeating command RepeatingCommand, which can be used to run the command more than once. Start it with Scheduler.get().scheduleIncremental() that will execute the command until the execute method returns false. You can use this to split tasks into sub tasks to get better 'threading' behavior. The Scheduler supports some additional methods to start a scheduled command differently. See the JavaDoc for more details.
Edited and updated with new GWT class instead of the deprecated DeferredCommand.
There is work on Web Workers as part of HTML5 that is implemented in a number of browsers, but not on all (most notably internet explorer). You could use these features where available, but what you should do is look at the javascript programming model.
Javascript generally works asynchronously. Requests are fired off and at some point their answers are received as an event. You can have a large number of pending requests at the same time. This will require a bit of a redesign of your system though.
New way is to use a Scheduler
JavaScript doesn't support multithreading, so whatever GWT does, multithreading has to be done solely on the server side, because GWT can only use features that are already available on the client side.