-
-
Notifications
You must be signed in to change notification settings - Fork 77
Run Background service Error #86
Comments
Hi @p3r4f089, Thanks for reporting this exception! I added a background service in the Demo app trying to reproduce the issue but everything is working as expected. The demo is now toasting the current location every 3 seconds even if the app is not active. Could you check the differences between your code and the code in pull request #87 and update us back? |
when the app is running in the background works as expected, the problem starts when i kill the app , the service keeps running but the call to the location method gets an error as shown above. |
Hi @DimitarTachev I used the background service demo and it worked correctly, but when i try to get the position outside of the service it fails. my code:
and Error |
getting same error, some google play service available check messed up?? Error: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.PackageManager android.content.Context.getPackageManager()' on a null object reference |
For nativescript-gelocation plugin, if I change line 194 in file geolocation.android.js from Crash does not occur, the "application_1.android.foregroundActivitity" is not defined for background services? Whereas application_1.android.context is always defined. |
@p3r4f089 Using the demo app I'm unable to reproduce the error. I'm getting position using the Get Current Location button which is outside the service. Can you elaborate a bit more and provide a complete example? Maybe I miss something. |
I'm getting the current location inside the service, the variable application_1.android.foregroundActivity is null inside the service, but it you use application_1.android.context instead in call to googleApiAvailability.isGooglePlayServicesAvailable everything works. on line 194 in geolocation.android.js file. With this change everything works fine inside service or in foreground of app. |
@agrw Thank you! This works! Administrators must upload this change to the repository |
- activate background monitoring with a button instead of on startup - apply fix suggested in #86
- activate background monitoring with a button instead of on startup - apply fix suggested in #86
|
Which platform(s) does your issue occur on?
Please, provide the following version numbers that your issue occurs with:
"version": "3.2.0"
}
"dependencies": {
"buffer": "^5.0.8",
"js-base64": "^2.3.2",
"moment": "^2.19.1",
"native-socket": "file:./files/Nativesocket",
"nativescript-android-utils": "^1.0.2",
"nativescript-bootreceiver": "^1.0.0",
"nativescript-checkbox": "^3.0.1",
"nativescript-couchbase": "^1.0.18",
"nativescript-geolocation": "4.2.0",
"nativescript-loading-indicator": "^2.4.0",
"nativescript-localize": "^2.0.1",
"nativescript-mapbox": "^3.1.2",
"nativescript-permissions": "^1.2.3",
"nativescript-pulltorefresh": "^2.0.2",
"nativescript-secure-storage": "^2.2.1",
"nativescript-theme-core": "~1.0.2",
"nativescript-toast": "^1.4.6",
"netchecksum": "^0.1.1",
"timrjs": "^1.0.1",
"tns-core-modules": "^3.2.0",
"tns-ios": "3.2.0",
"validator": "^8.2.0"
},
"devDependencies": {
"awesome-typescript-loader": "~3.1.3",
"babel-traverse": "6.25.0",
"babel-types": "6.25.0",
"babylon": "6.17.4",
"copy-webpack-plugin": "~4.0.1",
"extract-text-webpack-plugin": "^3.0.1",
"lazy": "1.0.11",
"nativescript-css-loader": "~0.26.0",
"nativescript-dev-sass": "^1.3.2",
"nativescript-dev-typescript": "^0.5.1",
"nativescript-dev-webpack": "^0.8.0",
"nativescript-worker-loader": "~0.8.1",
"raw-loader": "~0.5.1",
"resolve-url-loader": "^2.1.1",
"tns-platform-declarations": "^3.1.1",
"typescript": "^2.5.3",
"webpack": "~3.2.0",
"webpack-bundle-analyzer": "^2.8.2",
"webpack-sources": "~1.0.1"
},
Please, tell us how to recreate the issue in as much detail as possible.
I have a service background and call watch or get position, with version 3.0.1 of the plugin well ok, but whit minors errors, I'am test with versions 4.1.0 and 4.2.0 and
It works very well, so when app is open everything work ok, but when app is close and de service run on background mode i have a error, I'm using
android.app.Service.extend("com.tns.nativescript", {
onStartCommand: function(intent, flags, startId) {
this.super.onStartCommand(intent, flags, startId);
return android.app.Service.START_STICKY;
},
onCreate: function() {
watchLocation(); // here call wathc or get position
},
onBind: function(intent) {
console.log("on Bind Services");
},
onUnbind: function(intent){
console.log('UnBind Service');
},
onDestroy: function(){
console.log('service onDestroy);
}
});
Error:
Error: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.PackageManager android.content.Context.getPackageManager()' on a null object reference
com.google.android.gms.common.zzo.isGooglePlayServicesAvailable(Unknown Source)
com.google.android.gms.common.zze.isGooglePlayServicesAvailable(Unknown Source)
com.google.android.gms.common.GoogleApiAvailability.isGooglePlayServicesAvailable(Unknown Source)
com.tns.Runtime.callJSMethodNative(Native Method)
com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1084)
com.tns.Runtime.callJSMethodImpl(Runtime.java:966)
com.tns.Runtime.callJSMethod(Runtime.java:953)
com.tns.Runtime.callJSMethod(Runtime.java:937)
com.tns.Runtime.callJSMethod(Runtime.java:929)
com.tns.gen.java.lang.Runnable.run(Runnable.java:10)
android.os.Handler.handleCallback(Handler.java:739)
android.os.Handler.dispatchMessage(Handler.java:95)
android.os.Looper.loop(Looper.java:148)
android.app.ActivityThread.main(ActivityThread.java:5417)
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
The text was updated successfully, but these errors were encountered: