How can I create background service with Ionic?

I am going to create mobile network call app with Ionic 2.
I have created login screen of the app.
If login is successful, the app screen disappear and the app switches to background mode.
And when the user click the app icon again, the user can close this app.
How can I do this?
I already used cordova-plugin-background-mode plugin.
The app works in background mode, but the app screen doesn’t disappear.
And when I click the android device back button, the app close.

Not sure if this info will be useful for the OP (6 months later) but it may be for future people with the same problem.

Check out the thread on this issue: https://github.com/katzer/cordova-plugin-background-mode/issues/279

You can also use the .moveToBackground() method of BackgroundMode to send the app to the background.

Word of warning: the BackgroundMode plugin is really good at draining users batteries as it is a very brute force way of making sure your app is able to perform operations when not in the foreground. I used it for my app but am now investigating alternate methods for adding the functionality I require because of the battery issue.

2 Likes

Hi, have you reached a solution? (the battery issue on BackgroundMode)

I ended up writing a custom cordova plugin that comes alive and executes JS code when there is a task for it to do. It greatly improved my battery situation but required writing native code. No I am not publishing the plugin because it contains very project specific code and wouldn’t be usable to others.

  • Gabe