简体   繁体   English

减少Android中的应用程序CPU使用率

[英]Reduce app CPU Usage in Android

My app shows a splash screen for 4 seconds and then opens another activity with a web view. 我的应用程序显示启动屏幕4秒钟,然后使用Web视图打开另一个活动。 I am using a thread to splash the screen and finish() the first activity as soon as web view activity is started. 启动Web视图活动后,我正在使用线程启动屏幕并完成第一个活动。 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. 它的CPU使用率在8%至23%之间波动。这可能是原因。 I want to reduce the CPU usage. 我想减少CPU使用率。 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? 听说使用了很多CPU?

import android.graphics.*

Are you using a AVD? 您正在使用AVD吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM