Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save NathanWalker/d171d89aee20234cb376793bda5094e0 to your computer and use it in GitHub Desktop.
Save NathanWalker/d171d89aee20234cb376793bda5094e0 to your computer and use it in GitHub Desktop.
NativeScript for Angular (No UI) module to handle only background services
@NgModule({
imports: [NativeScriptModule],
})
export class BackgroundModule {
ngDoBootstrap() {
// do nothing, this is not an UI module
}
}
const moduleRefPromise = platformNativeScript().bootstrapModule(AppModule);
@JavaProxy("com.example.SomeEventReceiver")
@NativeClass()
class SomeEventReceiver extends android.content.BroadcastReceiver {
onReceive(
context: android.content.Context,
intent: android.content.Intent
): void {
console.log("INTENT RECEIVED");
this.doBackgroundFetch();
}
async doBackgroundFetch() {
const moduleRef = await moduleRefPromise;
moduleRef.injector.get(BackgroundService).fetchLatestDataAndSaveToDisk();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment