App is draining your battery

Can anyone tell me what the best steps are for finding out why an app might be causing a battery drain warning? Is it likely to be a memory leak? Could it be a case of not unsubscribing to a subscription of some sort when a component is removed from memory?

So far the warning appears only on one phone (a Samsung device running Android 7). A warning appears and on the Battery- Draining Apps screen our app is listed along with a message saying this app should be put to sleep to extend battery life.

Keen to know the best steps to take in order to find out why this is happening. Thanks.

1 Like

Step 1:
What is the app doing?
What plugins / native code is it using?
is it actually a problem or only a warning on a test device that isn’t used with any other apps (so limited data to compare)?

1 Like

The app was installed on the device, the user opened it and did a few tests, re-opened it the following day and closed it again. Then the warning appeared (which we obviously don’t want appearing on users devices). I’m not sure what other apps the user was using during that test period but regardless of that we do not want this warning appearing for our application.

The app should not be doing anything whilst in background (we do use Push Notifications though). Previously the app was subscribing to a realtime data service (faye) but the app unscubscribes to this on the pause event and re-subscribes to it on resume.

Here’s our current plugin list:

cordova-plugin-app-version 0.1.9 "AppVersion"
cordova-plugin-badge 0.8.2 "Badges"
cordova-plugin-calendar 4.6.0 "Calendar"
cordova-plugin-compat 1.1.0 "Compat"
cordova-plugin-crosswalk-webview 2.3.0 "Crosswalk WebView Engine"
cordova-plugin-device 1.1.6 "Device"
cordova-plugin-dialogs 1.3.3 "Notification"
cordova-plugin-file 4.3.3 "File"
cordova-plugin-http 1.2.1 "SSL Pinning"
cordova-plugin-inappbrowser 1.7.1 "InAppBrowser"
cordova-plugin-network-information 1.3.3 "Network Information"
cordova-plugin-splashscreen 4.0.3 "Splashscreen"
cordova-plugin-statusbar 2.2.3 "StatusBar"
cordova-plugin-touch-id 3.2.0 "Touch ID"
cordova-plugin-whitelist 1.3.2 "Whitelist"
cordova-plugin-wkwebview-engine 1.1.5 "Cordova WKWebView Engine"
ionic-plugin-deploy 0.6.7 "IonicDeploy"
ionic-plugin-keyboard 2.2.1 "Keyboard"
phonegap-plugin-push 1.10.5 “PushPlugin”

Thanks for taking a look. I’ve not really had to deal with this before so am keen to know best steps and I’m sure this would help others too.

Ok, so no regular update check or polling to a server?
No bluetooth or any other device APIs used that could run “over time”?
How is that realtime data service implemented?

What is the ionic info for the app?

1 Like

No polling to the server, no. The realtime library is implemented as in the instructions here . As I said, I unsubscribe and re-subscribe to this on pause and resume so hopefully that is ok. Ionic Info:

cli packages: (/Users/richardshergold/IonicProjects/myApp/myApp/node_modules)

    @ionic/cli-utils  : 1.17.0
    ionic (Ionic CLI) : 3.17.0

global packages:

    cordova (Cordova CLI) : 7.1.0

local packages:

    @ionic/app-scripts : 3.1.4
    Cordova Platforms  : android 6.2.3 ios 4.5.0
    Ionic Framework    : ionic-angular 3.9.2

System:

    ios-deploy : 1.9.2
    Node       : v6.11.4
    npm        : 2.15.12
    OS         : macOS High Sierra
    Xcode      : Xcode 9.1 Build version 9B55

Environment Variables:

    ANDROID_HOME : not set

Misc:

    backend : pro

I would still guess this is the most probable candidate for battery issues. If it is active all the time when your app is running, this sure needs resources. (And all the other stuff seems harmless in comparison)

Android Studio has some ways to measure battery usage I think. Maybe find out how that works and do stuff with your app on a connected device to see how different functionality influences battery usage.

1 Like

Thanks @Sujan12 - I will take a look at it again.

Hi, @richardshergold, did you ever resolve this issue? My team is currently experiencing a similar issue with an ionic app. If you have learned anything since your last post about what might cause this problem or how to track down the source, I would be grateful if you could update this thread and share your knowledge.

Thanks!.