Hello,
I’m trying to figure out, if it is possible, to run http request function with time interval and alert popup message window, from moment of Ionic2 apk installation on Android device and during background mode when application is closed.
For example if I use:
import { BackgroundMode } from '@ionic-native/background-mode';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/interval';
home.ts:
constructor(
public platform: Platform,
public backgroundMode: BackgroundMode
) {
platform.ready().then(() => {
this.backgroundMode.on('activate').subscribe(() => {
console.log('activated');
this.showNotification();
});
this.backgroundMode.enable();
})
}
to do something like this:
public background_function() {
this.backgroundMode.enable();
this.backgroundMode.on("activate").subscribe(() => {
this.sub = Observable.interval(3000).subscribe((val) => {
console.log('my http request function, executed every 3 seconds');
alert("and popup, executed every 3 seconds");
})
});
this.backgroundMode.enable();
}
But seems like it does not works like this, not sure where and how I’ve to locate code to run function in background this way. Need help