Last active
June 30, 2022 04:10
-
-
Save NathanWalker/d171d89aee20234cb376793bda5094e0 to your computer and use it in GitHub Desktop.
NativeScript for Angular (No UI) module to handle only background services
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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