Background service in ionic


#1

Hi,
I’m using ionic v2 ,I need to create an app (Android) which send and receive data from php server …
I want to do this even if the user kill the application…
Can it be done by ionic ?.
If so how?


#2

This is not possible with any development framework. Explicit killing of apps… kills them.


#3

i mean when the app is closed ,
for example ,like whatsapp it will automatically download messages and send message /images when there is internet connection ,even the application not running


#4

Use cordova plugin background mode


#5

Yes, this might be a problem to be solved with https://ionicframework.com/docs/native/background-mode/. But again, this only works when the app is running.

What you see for Whatsapp and many other messengers are just push notifications that your phone receives. The actually message are only loaded when you start the app.


#6

Background mode only work when the application is open,
And i don’t think with this i could achieve what am aiming for!


#7

I’m unsure what your definition of background is then, but as Sujan12 has said it sounds like the solution you’re looking for is push notifications.


#8

Think about this from a user perspective. Would you want an app that is constantly chewing up your battery when it isn’t even running?


#9

Background mode will execute when the user will open the app once atleast. Then if they tap on home button or exit the app, the background plugin will take over and create a persistent notification in android. this will keep the webview working for your hybrid app. Checkout the repo of the plugin for example. I created an app which runs in background on android.

For something like whatsapp, they use push notifications.


#10

My aim is to upload some images to the server i’m able to do this when the user in the app/screen ;But if the user close the app or minimize the app i cloudn’t do it…
i want to achieve this,even the app is closed by user the image should be sent to server if there is internet connection…By using the background mode plugin ,Can i do this?


#11

i am using background plugin to send the data to server when app is in minimize mode(no kill) as i keep my data in sqlite . You can do that


#12

You need to experiment with this.


#13

i will try … thanks


#14

could you please tell me how to use the ON instance at ionic…
i have tried "this.backgroundMode.on(‘activate’, function () {

})

but it shows error


#15
  this.backgroundMode.onactivate().subscribe(() => {
     
})

do something like this.


#16

Try this

startTrackingLocation() {

    console.log('Start geotracking');

    console.log('Is background mode active: ',this.backgroundMode.isActive());
    this.backgroundMode.isActive() === true?this.trackGeoBackground():this.trackGeoForeground();



    this.backgroundMode.on('activate').subscribe(() => {


        this.stopTrackingGeoForeground();
        this.trackGeoBackground();
    });
    this.backgroundMode.on('deactivate').subscribe(() => {
        this.stopTrackingGeoBackground();
        this.trackGeoForeground();
    });

}

#17

my app was working fine. I decided to install background mode plugin to process in background so that it will give a notification when user reached near certain location. But when i install the plugin and included in the module file and in my working file then app stops working without any error. Then I run my app removing this plugin and again it works fine. I am using ionic 3. I found somewhere that this plugin doesn’t work in ionic 3. Is this true? any solution please


#18

Did you find a solution? I need to send user’s coordinates to server even user kill the application. How should i do that? Can anyone help me?


#19

Use the plugin

Every 10 Sec , This plugin update location coordinate to url

check out


#20

I check it. It can track even user kill the application. I need to send coordinates to my database. How can i do that while not running application. Do you have any idea?