-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
background service? #2
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
Yes same question |
👍 |
I need to know the same thing, anybody? ;-) |
Currently, NativeScript for Android does not support this scenario (at least we haven't tested it). However, this is technically possible and we will provide support for it. |
Please use this issue: #85 |
There are 2 thread referencing each other ... is this ticket issues/2 the main one for commenting on background threads, or is this?: #85 |
+1 |
This comment was marked as abuse.
This comment was marked as abuse.
@NathanaelA this issue looks closed however. @slavchev would it be possible to re-open this? Or is there a general ticket covering this issue for IOS and Android? Thanks. |
Is it possible that the service is in a library / jar and running the service from ns? |
Currently NativeScript runtime for Android (you mentioned jar library) does not support this scenario though it is technically possible. I would suggest to keep this issue closed as there are other issues on this topic, for example #85, with active discussion. |
OK, since its quite different, we must solve these 2 problems I think . notifications is quite important as responsiveness of the ux . thanks |
+1 this is essential for apps that incorporate functionality like geo-fencing and event reminders. We need to be able to have a background service running. |
+1 i wish if there any way to make background service with nativescript |
+1 Need this for a simple app that reports the users location periodically even in the background. This requires a service for Android as best I can tell |
+1 |
When does NativeScript plans to implement background services? We need to show reminders to users when they are not using the application. |
@erkanarslan I think you can use local notifications for this, I haven't used it but that is my understanding. |
I wondered if it's possible to create service in Android studio then call the nativescript app? |
@Daxito Thank you. I found how to create local notifications and server push notifications: There is no need to run a service to show notifications, reminders or receive chat messages. |
+1 to create a Create a Service that can run all the time. For us it would be perfect to get data from our servers to update Today extension and android widget. |
@AntonioCuevaUrraco You can use https://github.com/NativeScript/push-plugin. This plugin will get messages from internet even if application is not running. |
is anyone able to make this example work? |
@andrew19881123 You need to run it using the pre-generated platforms folder provided. Corresponding java files have been added to the platforms/android/src/main/java/com/tns folder. |
@andrew19881123 I will have a look at it tomorrow. @boxgundam there are some changes with today's release (2.3.0). We no longer generate |
@andrew19881123 I checked the example project and so it works as expected. I saw you already created issues (NativeScript/sample-android-background-services#1 and NativeScript/sample-android-background-services#2) so I would suggest to move the discussion there. |
@slavchev can you provide a sample for background-service with nativescript angular ? |
@sadiqna I am not aware of sample for background service with NativeScript+Angular but it shouldn't be hard to adjust the existing sample. Basically, all (most) of the Angular things in NativeScript are related to UI and application components. For Android background services all you need is a service implementation and the according changes in Anyway, I would suggest to ask in {N} community Slack channel. |
This is how I made a service that runs in the background in NativeScript: SomeService.js: // I'm using toast to check that the service restarts once I close the app
var Toast = require("nativescript-toast"); //tns plugin add nativescript-toast
android.app.Service.extend("com.something.SomeService", {
onStartCommand: function(intent, flags, startId) {
this.super.onStartCommand(intent, flags, startId);
return android.app.Service.START_STICKY;
},
onCreate: function() {
var toast = Toast.makeText("SomeService STARTED");
toast.show();
},
onBind: function(intent) {
console.log("##onBind NOT YET IMPLEMENTED");
}
})
module.exports = {} then, in my main.js view controller: const SomeService = require("./SomeService");
const utils = require("utils/utils");
function onPageLoaded() {
var context = utils.ad.getApplicationContext();
var intent = new android.content.Intent(context, com.something.SomeService.class);
context.startService(intent);
} Also, don't forget to add the service to the manifest file <service android:name="com.something.SomeService"
android:exported="false" >
</service> |
@surdu does this code still work? I'm using tns-android 3.2, and android.app is not found
|
Okay got it, for others coming here in the future. If you're using typescript, do the following
|
@Liooo I'm not using this exact code in my app anymore, but it should still work. I needed it to track locations in background and figured out I don't need a continuously running background service for that. And yeah, maybe I should have mentioned that that code is written in vanilla JS version of {N} 😅 |
@surdu thanks for the reply, and yea it will still work for vanilla JS {N}.
Oh I'm doing the same thing, and if we want the location tracking to work even when the app is in the background or killed, we need Service don't we? (sorry it's bit off track from the original issue tho) |
@Liooo No, you don't 😄 You need to create am instance of IntentService like so:
You will need this plugin for the above code in order to be able to declare IntentServices with an empty constructor. Then, when you request for the location updates, you pass the class created above .
What I didn't realize, is that the Note: the code is mostly copy & pasted for reference only, it will not work as-is. If you don't manage to figure out the missing parts, please let me know ;) Also, we are now working on an open source natives script plugin that will allow you to use location tracking in background. The code was copy pasted from that 😄 |
@surdu com.pip3r4o.android.app.IntentService.extend("com.my.IntentService", { |
@c1ngular Yes, it depends on Google Play Services. I believe there are no other alternatives, but I don't think there is an Android phone without Google Play Services ... I mean how do you install the app on the phone otherwise ? |
Talk to someone from China or Iran |
@c1ngular According to this you do have an alternative to Google Play Services when it comes to location. I don't know if for that you still have the ability to use it in the background without a continuously running service. Here you have some more details: https://stackoverflow.com/a/33023788/460750 |
If you want an alternative to play-services, with identical API, use this. |
@surdu @christocracy thanks ! |
TabLayout for NativeScript tabs
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
hi, would it be possible to create a background service with native script?
thx, dan
The text was updated successfully, but these errors were encountered: