How to run app forever in background like whatsapp?

what is MyService.java? Is it empty folder? Please help me?

if not created folder name sample automatically do manually create java file in it

no you need to extend backgroundservice see that basic plugin u wil got to know whats in inside

add service code inside androidmanifest.xml

How can i achieve this on Ionic 3?

1 Like

Ok your native solution works for Android , what about IOS ?

Do you have any example or something?

Basically, it’s what Auro has explained.
But in a more practice way, I have a main controller that connects in the server, loads the app’s database (sqlite) and just then loads the result in the screen.

When the app is closed, the app is stopped. When something happen in server, a push notification is sent and when the user opens the app, the main controller does those steps and show the results updated in the screen.

There is no secret. But maybe the big trick is to set “cache:false” in the “.state” in your app.js when configuring the routes.
This grarantee that everytime the view is fired, its controller is also fired, executing all the functions again (Actually I’m not sure if this will make any diference in this process, but, anyway… just imagining the problems you maybe are going through).

Ex.:

.config(function($stateProvider, $urlRouterProvider) {
  $stateProvider
.state('app.panel', {
    cache: false,
    url: '/panel',
    views: {
      'menuContent': {
        templateUrl: 'templates/panel.html',
        controller: 'PanelCtrl'
      }
    }
  })

But if you could not do the trick, tell me what you are getting and maybe I can help.

How to use this in ionic 2 ???

Hello @sajith,

Please can you solve this. I can’t understand your solution.

Hi all, I solved my background issue with backgroundMode plugin provided by ionic team:


Hope it will be help.

Hi, can you tell me where to put

this.backgroundMode.enable();

in the project files?

you can use it any where you want., for example you can use it inside a functions and call it.

it can use for IOS ?