Using cpu android application in android phone in background

I make a phonegap application for Android, but I stick to the following: When I use the application and check the task, the application still consumes a significant amount of CPU (from 5%, and sometimes up to 15%). I tried to remove all other parts of my code, but the only thing that stops the application from CPU activity in the background is to remove phonegap.js from my code.

I got the impression that Phonegap would stop javascript execution when entering onPause, but something is missing for me.

I tried 1.1.0, 1.2.0 and 1.3.0 to no avail. It is also interesting that if I launched 2 telephony applications, their background CPU usage seems to behave the same: one goes up, the other goes up and basically they are accurate in use to a percentage point.

Has anyone understood what the application is still doing on the CPU and / or how can I find out?

Hello

+4
source share
3 answers

js execution does not stop when the application goes into onPause, it stops only when the application is closed / disconnected.

+2
source

Cordoba / PhoneGaps default behaivior is to keep the application in the background, you can change it by adding the keepRunning tag to your config.xml:

keepRunning (boolean, defaults to true) - Determines whether Cordoba will run in the background or not.

<preference name="keeprunning" value="false"/> 
+1
source

I noticed the same problem, especially on KitKat. To fix this problem, in your main action (an activity that extends DroidGap) you need to call the onPause () method on your WebView (which is the "appView" variable).

This suspends any additional processing associated with WebView that should significantly reduce CPU usage:

 @Override protected void onPause() { super.onPause(); if (appView != null) { appView.onPause(); } } @Override protected void onResume() { super.onResume(); if (appView != null) { appView.onResume(); } } 
0
source

Source: https://habr.com/ru/post/1391229/


All Articles