How to run app forever in background like whatsapp?

i have same issue, no idea how to solve it.

i have same issue anyone solved the issue.is there any plugin available for background service

Do I just put the sample code in

.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
?

Ii got an error like :require is not defined in background-mode.js

var exec = require(‘cordova/exec’);
var channel = require(‘cordova/channel’);

Do you have any idea why?

Hi, I have a similar scenario… Do you have any solution for this case? thx

2 Likes

Even i am facing same issue i need to run the app in the background ! Any idea i tried with MyService but didn’t get whether it was working or not.

Any support would greatly be appreciated !

any solution, I have the same problem ?

Nothing yet. We try many plugins and nothing is working like a service.

Hey all. I use these plugins in conjunction and my app works in background successfully on back button.

  1. Katzer-Background Mode and
  2. Mohamed Salah - Back Button

So according to what my app logic is, I put my app on bg mode when necessary

I’m testing for Iphone primaly (which is the one freezing the app after a few mins of no use to avoid backgroung usage)… and even when the backgroun process works (I ‘beep’ every 10 mins to know that is running in the backbroung) is using lots of power to keep it alive… there is nothing huge happening… just a ‘interval’ running every 10 minutes, doing a beep and waiting again… don’t know how to make it less battery hungry… is not like doing lots of work

Best when you want to give Android control over wake up, and can live with periodically waking up your code. Simply use an AlarmManager to invoke a Service class at regular intervals. Here is some code from my LifeLog24 app:

where is the code lineisyJanelle

FINALLY I GOT

1.plugin —
org.apache.cordova.background-service=https://github.com/Red-Folder/bgs-core.git

2.script inside plugin folder copy backgroundservice.js and add it into your js folder

3.inside com.red_folder.phonegap.plugin.backgroundservice folder/package create a folder name called sample and add Myservice.java or yours any class related to service see plugin
make sure after adding platform ‘android’ inside that check whether the sample folder created inside assests/plugins/com.red_folder.phonegap.plugin.backgroundservice/sample

4.open platforms/android/AndroidManifest.xml
add this service code
service android:name=“com.red_folder.phonegap.plugin.backgroundservice.sample.MyService”>
<intent-filter <action android:name=“com.red_folder.phonegap.plugin.backgroundservice.sample.MyService”/
</intent-filter </service

5.in main controller or config

document.addEventListener('deviceready', function () {
      var serviceName = 'com.red_folder.phonegap.plugin.backgroundservice.sample.MyService';
    var factory = cordova.require('com.red_folder.phonegap.plugin.backgroundservice.BackgroundService');
    myService = factory.create(serviceName);
    alert(JSON.stringify(myService));
    startService();
},true);


function getStatus(){
  myService.getStatus(function(r) {
	$scope.handleSuccess(r)
}, function(e) {
	$scope.handleError(e)
});
}

function stopService() {
                myService.stopService(function(r) {
                   $scope.handleSuccess(r)
                },
                        function(e) {
                             $scope.handleError(e)
                        });
            }


function startService() {
    myService.startService(function (r) {
        $scope.handleSuccess(r)
        if(r.ServiceRunning){

                    setConfig()
                     enableTimer();
                     registerForUpdates()
                     registerForBootStart()
        }
    },
            function (e) {
                $scope.handleError(e)
            });
}
function enableTimer() {
    myService.enableTimer(10000,
            function (r) {
                 $scope.handleSuccess(r)
            },
            function (e) {
                $scope.handleError(e)
            });
}
function registerForBootStart() {
       myService.registerForBootStart(function (r) {
         $scope.handleSuccess(r)
       },
               function (e) {
                   handleError(e)
               });
   }

   function registerForUpdates() {
       myService.registerForUpdates(function (r) {
         $scope.handleSuccess(r)
       },
               function (e) {
                   $scope.handleError(e)
               });
   }
   function setConfig() {

       var helloToString = "saji";
       var config = {
           "HelloTo": helloToString
       };
       myService.setConfiguration(config,
               function (r) {
                  $scope.handleSuccess(r)
               },
               function (e) {
                   $scope.handleError(e)
               });
   }


$scope.handleSuccess = function (data) {

    alert("sucess" + JSON.stringify(data));
    th.data = data;

}
$scope.handleError = function (data) {

    alert("error" + JSON.stringify(data))
    th.data = data;

}
1 Like

Hello Sajith

Can you please send a sample app ?

i dont have that app now can you tell me which scenario you are getting error?

This point is not working for me…

background service will not work inside javascript we need to write service for that so just followed that steps and had writen service code inside java file after that only we need to call that function through js…

I have this error:
Plugin unable to bind to background?
I don´t what happend here?

How can I attain similar solution for IOS? I think the solution will only be working on Android devices.

Can u please tell me?

How to use ionic 2…

4 Likes

Hey, man, that routine was exactly what I needed to know. Thanks for that!