Java Question Getting an answer from b4a in a Event which is raised

DonManfred

Expert
Licensed User
Longtime User
https://www.b4x.com/android/forum/threads/firebase-jobdispatcher.85613/

The wish here is about the firebase Jobdispatcher.

For this one need to write a service which then extends their JobService. Inside this service the developer need to answer (give a true/false result).

Is it possible to raise an event in B4A (probably used inside starter) from this java-service AND to get back an Answer from the B4A Event which is raised?

This is a basic service for this...
B4X:
import com.firebase.jobdispatcher.JobParameters;
import com.firebase.jobdispatcher.JobService;

public class MyJobService extends JobService {
    @Override
    public boolean onStartJob(JobParameters job) {
        // Do some work here

        return false; // Answers the question: "Is there still work going on?"
    }

    @Override
    public boolean onStopJob(JobParameters job) {
        return false; // Answers the question: "Should this job be retried?"
    }

[..]
}
In onStartJob for example i would like to raise an event to b4a.
But it must be somehow synchronours or so. I need to get the answer to return true/false to the base service...

Can someone help me with an example on how this would work?
 

DonManfred

Expert
Licensed User
Longtime User
Check this example
In this case (i´ve written a similar Service) i get the error

B4A Version: 7.30
Parse den Code. (0.00s)
Kompiliere den Code. (0.02s)
Kompiliere Layoutcode. (0.00s)
Organisiere Libraries. (0.00s)
Generiere R Datei. (0.04s)
Kompiliere generierten Java Code. Error
javac 1.8.0_141
src\b4a\example\dispatch.java:63: error: onStart(Intent,int) in dispatch cannot override onStart(Intent,int) in JobService
public void onStart(android.content.Intent intent, int startId) {
^
overridden method is final
Note: src\b4a\example\starter.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error

Based on their docu a minimal Service can look like this:

The simplest possible JobService:
B4X:
import com.firebase.jobdispatcher.JobParameters;
import com.firebase.jobdispatcher.JobService;

public class MyJobService extends JobService {
    @Override
    public boolean onStartJob(JobParameters job) {
        // Do some work here

        return false; // Answers the question: "Is there still work going on?"
    }

    @Override
    public boolean onStopJob(JobParameters job) {
        return false; // Answers the question: "Should this job be retried?"
    }
}

So i can not override the onstart method here....
 

tigrot

Well-Known Member
Licensed User
Longtime User
I have read the Firebase jobdispatcher three times and I was not able to understand what it is for.
Also the issue that Don found in example is a little strange...
Can somebody try to explain to this poor old IT man the functions of this scheduler?
Thank you!
Mauro
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
In this case (i´ve written a similar Service) i get the error
I see. You will not be able to use #Extends in this case as they made the onStart method a final method.

While there are other options available to communicate with external services, I wouldn't recommend wrapping this specific library unless you are very familiar with Android services internal life cycle. It will be "easy" to create a wrapper that works in most cases and fail in less common cases.
 
Top