Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit fce3921

Browse files
author
Elena Hristova
committed
remove background services from new demo projects
1 parent 0009b24 commit fce3921

File tree

7 files changed

+0
-275
lines changed

7 files changed

+0
-275
lines changed

demo-angular/App_Resources/Android/src/main/AndroidManifest.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,6 @@
2424
android:icon="@drawable/icon"
2525
android:label="@string/app_name"
2626
android:theme="@style/AppTheme">
27-
28-
29-
<service android:name="com.nativescript.location.BackgroundService"
30-
android:exported="false" >
31-
</service>
32-
33-
<service android:name="com.nativescript.location.BackgroundService26"
34-
android:permission="android.permission.BIND_JOB_SERVICE"
35-
android:enabled="true"
36-
android:exported="false">
37-
</service>
3827

3928
<activity
4029
android:name="com.tns.NativeScriptActivity"

demo-angular/src/app/background-service.ts

Lines changed: 0 additions & 79 deletions
This file was deleted.

demo-angular/src/app/home/home.component.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
<Button text="Start Monitoring" col="2" textWrap="true" (tap)="buttonStartTap()"></Button>
1010
<Button text="Stop Monitoring" col="3" textWrap="true" (tap)="buttonStopTap()"></Button>
1111
</GridLayout>
12-
<GridLayout row="1" columns="*, *" >
13-
<Button text="Start Background thread monitoring" col="0" ios:visibility="collapsed" textWrap="true" (tap)="startBackgroundTap()"></Button>
14-
<Button text="Stop Background thread monitoring" col="1" ios:visibility="collapsed" textWrap="true" (tap)="stopBackgroundTap()"></Button>
15-
</GridLayout>
1612
<ListView row="2" [items]="locations">
1713
<ng-template let-item="item">
1814
<Label text="{{ item.latitude + ', ' + item.longitude + ', ' + item.altitude }}" ></Label>

demo-angular/src/app/home/home.component.ts

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { Component, OnInit } from "@angular/core";
22
import * as geolocation from "nativescript-geolocation";
33
import { Accuracy } from "tns-core-modules/ui/enums";
4-
import * as application from "tns-core-modules/application";
5-
import { device } from "tns-core-modules/platform";
6-
const utils = require("tns-core-modules/utils/utils");
74

85
@Component({
96
selector: "Home",
@@ -14,28 +11,15 @@ export class HomeComponent implements OnInit {
1411

1512
locations = [];
1613
watchIds = [];
17-
jobId = 308; // the id should be unique for each background job. We only use one, so we set the id to be the same each time.
1814

1915
constructor() {
2016
// Use the component constructor to inject providers.
2117
}
2218

2319
ngOnInit(): void {
24-
application.on(application.exitEvent, this._stopBackgroundJob);
2520
// Init your component properties here.
2621
}
2722

28-
_stopBackgroundJob() {
29-
if (application.android) {
30-
let context = utils.ad.getApplicationContext();
31-
const jobScheduler = context.getSystemService((<any>android.content.Context).JOB_SCHEDULER_SERVICE);
32-
if (jobScheduler.getPendingJob(this.jobId) !== null) {
33-
jobScheduler.cancel(this.jobId);
34-
console.log(`Job Canceled: ${this.jobId}`);
35-
}
36-
}
37-
}
38-
3923
public enableLocationTap() {
4024
geolocation.isEnabled().then(function (isEnabled) {
4125
if (!isEnabled) {
@@ -98,32 +82,4 @@ export class HomeComponent implements OnInit {
9882
public buttonClearTap() {
9983
this.locations.splice(0, this.locations.length);
10084
}
101-
102-
// public startBackgroundTap() {
103-
// if (application.android) {
104-
// let context = utils.ad.getApplicationContext();
105-
// if (device.sdkVersion >= "26") {
106-
// const jobScheduler = context.getSystemService((<any>android.content.Context).JOB_SCHEDULER_SERVICE);
107-
// const component = new android.content.ComponentName(context, com.nativescript.location.BackgroundService26.class);
108-
// const builder = new (<any>android.app).job.JobInfo.Builder(this.jobId, component);
109-
// builder.setOverrideDeadline(0);
110-
// return jobScheduler.schedule(builder.build());
111-
// } else {
112-
// let intent = new android.content.Intent(context, com.nativescript.location.BackgroundService.class);
113-
// context.startService(intent);
114-
// }
115-
// }
116-
// }
117-
118-
// public stopBackgroundTap() {
119-
// if (application.android) {
120-
// if (device.sdkVersion >= "26") {
121-
// this._stopBackgroundJob();
122-
// } else {
123-
// let context = utils.ad.getApplicationContext();
124-
// let intent = new android.content.Intent(context, com.nativescript.location.BackgroundService.class);
125-
// context.stopService(intent);
126-
// }
127-
// }
128-
// }
12985
}

demo-vue/app/App_Resources/Android/AndroidManifest.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,6 @@
2323
android:icon="@drawable/icon"
2424
android:label="@string/app_name"
2525
android:theme="@style/AppTheme">
26-
27-
28-
<service android:name="com.nativescript.location.BackgroundService"
29-
android:exported="false" >
30-
</service>
31-
32-
<service android:name="com.nativescript.location.BackgroundService26"
33-
android:permission="android.permission.BIND_JOB_SERVICE"
34-
android:enabled="true"
35-
android:exported="false">
36-
</service>
3726

3827
<activity
3928
android:name="com.tns.NativeScriptActivity"

demo-vue/app/background-service.ts

Lines changed: 0 additions & 79 deletions
This file was deleted.

demo-vue/app/components/Home.vue

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
<Button text="Start Monitoring" col="2" textWrap="true" @tap="buttonStartTap"/>
1212
<Button text="Stop Monitoring" col="3" textWrap="true" @tap="buttonStopTap"/>
1313
</GridLayout>
14-
<!-- <GridLayout row="1" columns="*, *" >
15-
<Button text="Start Background thread monitoring" col="0" ios:visibility="collapsed" textWrap="true" @tap="startBackgroundTap"/>
16-
<Button text="Stop Background thread monitoring" col="1" ios:visibility="collapsed" textWrap="true" @tap="stopBackgroundTap"/>
17-
</GridLayout> -->
1814
<ListView row="2" for="item in locations">
1915
<v-template>
2016
<Label :text="item.latitude + ', ' + item.longitude + ', ' + item.altitude" />
@@ -28,23 +24,6 @@
2824
<script>
2925
import * as geolocation from "nativescript-geolocation";
3026
import { Accuracy } from "tns-core-modules/ui/enums";
31-
import * as application from "tns-core-modules/application";
32-
import { device } from "tns-core-modules/platform";
33-
34-
const utils = require("tns-core-modules/utils/utils");
35-
const jobId = 308; // the id should be unique for each background job. We only use one, so we set the id to be the same each time.
36-
37-
function _stopBackgroundJob() {
38-
if (application.android) {
39-
let context = utils.ad.getApplicationContext();
40-
const jobScheduler = context.getSystemService(android.content.Context.JOB_SCHEDULER_SERVICE);
41-
if (jobScheduler.getPendingJob(jobId) !== null) {
42-
jobScheduler.cancel(jobId);
43-
console.log(`Job Canceled: ${jobId}`);
44-
}
45-
}
46-
}
47-
application.on(application.exitEvent, _stopBackgroundJob);
4827
4928
export default {
5029
data() {
@@ -108,32 +87,6 @@
10887
watchId = this.watchIds.pop();
10988
}
11089
},
111-
startBackgroundTap: function() {
112-
if (application.android) {
113-
let context = utils.ad.getApplicationContext();
114-
if (device.sdkVersion >= "26") {
115-
const jobScheduler = context.getSystemService(android.content.Context.JOB_SCHEDULER_SERVICE);
116-
const component = new android.content.ComponentName(context, com.nativescript.location.BackgroundService26.class);
117-
const builder = new android.app.job.JobInfo.Builder(jobId, component);
118-
builder.setOverrideDeadline(0);
119-
return jobScheduler.schedule(builder.build());
120-
} else {
121-
let intent = new android.content.Intent(context, com.nativescript.location.BackgroundService.class);
122-
context.startService(intent);
123-
}
124-
}
125-
},
126-
stopBackgroundTap: function() {
127-
if (application.android) {
128-
if (device.sdkVersion >= "26") {
129-
_stopBackgroundJob();
130-
} else {
131-
let context = utils.ad.getApplicationContext();
132-
let intent = new android.content.Intent(context, com.nativescript.location.BackgroundService.class);
133-
context.stopService(intent);
134-
}
135-
}
136-
},
13790
buttonClearTap: function() {
13891
this.locations.splice(0, this.locations.length);
13992
}

0 commit comments

Comments
 (0)