-
-
Notifications
You must be signed in to change notification settings - Fork 136
Background job with WorkManager #1488
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
Comments
Hello @GrEg00z, thank you for the good description of the issue. I will take a look into the problem. |
Hi @GrEg00z :) I've made some changes in the runtime to handle the Android Worker classes. Could you try your sample with the runtime from the master branch: |
Hey @vmutafov, I tried the android platform at next version (6.2.0-2019-10-10-044952-01), but unfornatly I can't start the application. I get this error immadiatly when the app starts (1s after splashscreen appareas) : |
Hey @GrEg00z , are you by any chance using a Windows OS? |
Yes Im using windows 10 family edition (18362.356) Also, if I'm using the android runtime 6.1.2, or 6.1.1, my app stays locked to the splashscreen, without any error message or others, I just get this after few minutes in the console :
On 6.1.0, I don't have any problem with the app |
Any news about this ? |
Up please !! Nobody has problem with tns-android 6.1.1 or 6.1.2 ?? |
Hey did you manage to make it work? For me it works when I am running the code on devices with SDK > 26, but when running it on on devices with lower SDK I get the following error JS: ERROR Error: Uncaught (in promise): Error: java.lang.NoClassDefFoundError: java.time.Duration. |
Uh oh!
There was an error while loading. Please reload this page.
Environment
Provide version numbers for the following components (information can be retrieved by running
tns info
in your project folder or by inspecting thepackage.json
of the project):Gradle :
Describe the bug
I'm trying to implement WorkManager inside my nativescript app, to be able to schedule a background job (doc : https://developer.android.com/topic/libraries/architecture/workmanager/basics) .
The compilation and starting app is OK, but when Im trying to enqueue my job, it's not working because the Android Nativescript runtime is unable to initialize itself.
From Android Studio, I get this error :
To Reproduce
Declare a class in nativescript that extend Worker class :
Then a typescript class which will enqueue the job :
Here is the java class MyWorker generated by nativescript :
The problem is at the line :
com.tns.Runtime.initInstance(this);
If Im looking inside the class com.tns.Runtime, I can see this :
So what I suggest is the current Runtime is not initialized, because
getCurrentRuntime()
return null, soruntime.currentObjectId
throw an exceptionExpected behavior
Previously, I was using the library Firebase JobDispatcher (doc : https://github.com/firebase/firebase-jobdispatcher-android). It's using Android service, so the behaviour was different, but the generated class from nativescript was like that :
If you look the method
onCreate()
, you can see that there is a check on runtime initialization, and if not, the runtime is initialized.I suppose that is the missing part on my class, but I really don't know how to initialize the runtime by myself, before com.tns.Runtime.initInstance(this) is called in my generated class constructor
Sample project
As you can see, I put the minimum possible code on my class, you can simply copy paste my code and see what's going on
Additional context
My job consists to get the current location of the phone, every 15 minutes.
I'm still using JobDispatcher library to schedule this job in background, and its still working in my app (doc : https://github.com/firebase/firebase-jobdispatcher-android)
But now this library is deprecated., and they strongly recommand to switch on WorkManager system.
The main info is :
So until nativescript will target to Android Q, I hope to find a solution to use WorkManager (or a workaround to JobDispatcher)
The text was updated successfully, but these errors were encountered: