如何减少在Android手机应用程序的CPU使用率? [英] How to reduce App's CPU usage in Android phone?
问题描述
我公司开发的自动调用应用application.The。阅读文本文件,包括电话号码,并拨打了数第二和结束通话,并重复。
I developed auto-call application.The App. read text file including phone number list and call for a few second and end call and repeat.
我的问题是应用程序。不要送10〜16小时后调用。我不知道原因究竟,
但我想,这个问题是CPU usgae。我的应用程序的CPU占用率几乎是50%!
如何降低CPU使用率?
My problem is that App. do not send call after 10~16hours. I don't know the reason exactly, But I guess that the problem is CPU usgae. My App's CPU usage is almost 50%! How to reduce CPU usage?
下面是源$ C $ C的一部分。
我很抱歉,我的英语不好。
Here is part of source code. I'm sorry that my english is bad.
if(r_count.compareTo("0")!=0) {
while(index < repeat_count) {
count = 1;
time_count = 2;
while(count < map.length) {
performDial(); //start call
reject(); //end call
finishActivity(1);
TimeDelay("60"); // wait for 60sec
count = count + 2;
time_count = time_count + 2;
onBackPressed(); // press back button for calling next number
showCallLog();
finishActivity(0);
}
index++;
}
这是纯滞后()来源:
public void TimeDelay(String delayTime) {
saveTime = System.currentTimeMillis()/1000;
currentTime = 0;
dTime = Integer.parseInt(delayTime);
while(currentTime - saveTime < dTime) {
currentTime = System.currentTimeMillis()/1000;
}
}
纯滞后()重复while循环几次。
TimeDelay() repeat while loop for a few times.
推荐答案
它使用CPU的50%,其原因是,Android的显然不会让它使用CPU的100%,其中像在一个循环的纯滞后()
通常会。 (否则你有两个CPU,它使用一个CPU的100%是事实。)你在做什么叫做的忙等待,它应该是显而易见的,为什么不断地检查条件将使用大量的CPU。所以,不要做。使用视频下载()
来代替。然后,您的应用程序将在等待期间不使用CPU的。
The reason it's using 50% of your CPU is that Android apparently won't let it use 100% of the CPU, which a loop like the one in your TimeDelay()
ordinarily would. (Or else you have two CPUs and it is in fact using 100% of one CPU.) What you're doing is called a busy wait and it should be obvious why continually checking a condition will use lots of CPU. So don't do that. Use Thread.sleep()
instead. Your app will then use no CPU at all during the wait.
此外,偏偏,为什么你传递一个字符串,然后 parseInt函数
ING它,而不是仅仅通过一个整数
摆在首位? : - )
Also, for God's sake, why are you passing a string and then parseInt
ing it, rather than just passing an Integer
in the first place? :-)
这篇关于如何减少在Android手机应用程序的CPU使用率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!