降低Android应用程序CPU使用率 [英] Reduce app CPU Usage in Android

查看:998
本文介绍了降低Android应用程序CPU使用率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序显示了4秒的启动画面,然后打开一个Web视图另一项活动。
我使用一个线程尽快Web视图活动开始溅到屏幕并完成()的第一个活动。我也用类似淡入动画和淡出。
它的CPU使用率是8时23%之间%。什么可能的原因波动。我想降低CPU占用率。
  我的第一个活动,显示启动画面和启动Web视图活动 -

 公共类MainActivity延伸活动{
螺纹splashThread;
@覆盖
保护无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    overridePendingTransition(R.animation.fadein,R.animation.fadeout);    。getWindow()requestFeature(Window.FEATURE_NO_TITLE);
    getWindow()。setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);    的setContentView(R.layout.activity_main);
}@覆盖
保护无效调用onStart(){
    // TODO自动生成方法存根
     // -----------------------------------------        splashThread =新主题(){
        公共无效的run()
        {
            尝试
            {
                睡眠(1000);
            }
            赶上(例外五)
            {
                e.printStackTrace();
            }
            最后
            {
                意向意图=新意图(getApplicationContext(),OpenWeb.class);
                        startActivity(意向);
            }
        }
    };
    splashThread.start();
     // -----------------------------------------    super.onStart();
    overridePendingTransition(R.animation.fadein,R.animation.fadeout);
}
@覆盖
保护无效的onStop(){
    // TODO自动生成方法存根
    完();
    super.onRestart();
}
}


解决方案

可能是你使用进口的东西想了很多。我听说使用的CPU很多?

 进口android.graphics。*

您使用的是AVD?

My app shows a splash screen for 4 seconds and then opens another activity with a web view. I am using a thread to splash the screen and finish() the first activity as soon as web view activity is started. I have also used animations like fade in and fade out. It's CPU usage is fluctuating between 8% to 23%.What could be the reason. I want to reduce the CPU usage. My first activity that shows splash screen and starts web view activity-

           public class MainActivity extends Activity {
Thread splashThread;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    overridePendingTransition(R.animation.fadein,R.animation.fadeout); 

    getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.activity_main);
}

@Override
protected void onStart() {
    // TODO Auto-generated method stub
     //-----------------------------------------

        splashThread=new Thread(){
        public void run()
        {
            try
            {   
                sleep(1000);                    
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
            finally
            {
                Intent intent = new Intent(getApplicationContext(),OpenWeb.class);
                        startActivity(intent);
            }
        }
    };
    splashThread.start();
     //-----------------------------------------

    super.onStart();
    overridePendingTransition(R.animation.fadein, R.animation.fadeout);
}
@Override
protected void onStop() {
    // TODO Auto-generated method stub
    finish();
    super.onRestart();
} 
}

解决方案

Could be that you used alot of imports something like. I heard that uses alot of cpu?

import android.graphics.*

Are you using a AVD?

这篇关于降低Android应用程序CPU使用率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆