Search code examples
angularionic-frameworkcapacitor

How do create background service for Android in Ionic?


Tell me how in Ionic (I use Angular and Capacitor) to create function that, after building project on Android, will work even when application is closed (including after restarting the mobile phone)? It is required to make periodic POST requests to server and receive data (with open and closed application). If data on server is refreshed, I would like to display LocalNotifications from this background service.


Solution

  • Your question is composed of several questions.

    Runing after restart

    There is an Ionic plugin that can do this. Autostart

    Send request when application is closed

    You can use the Backgroud mode Ionic plugin.

    Display notification

    OneSignal can display notifications, sent from your backend, on your smartphone. There is also a Ionic plugin for OneSignal. The plugin will take care of being active even if your app is not and will also always be up, even after restart.