android – 如何提高以下代码的性能?

前端之家收集整理的这篇文章主要介绍了android – 如何提高以下代码的性能?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有以下代码显示一个图像与字母,
public class MainActivity extends Activity 
{
    private String[] capital_letters,small_letters;
    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void onStart()
    {
        super.onStart();

        try
        {
            capital_letters = getApplicationContext().getResources().getStringArray( R.array.capital_letters );
            small_letters = getApplicationContext().getResources().getStringArray( R.array.small_letters );

            MyAdapter adapter = new MyAdapter ( MainActivity.this,capital_letters,small_letters );
            ListView list = ( ListView ) findViewById( R.id.list );
            list.setAdapter( adapter );

            list.setOnItemClickListener( new AdapterView.OnItemClickListener() 
            {
                @Override
                public void onItemClick(AdapterView<?> arg0,View arg1,int position,long id ) 
                {
                    Intent intent = new Intent ( MainActivity.this,LetterActivity.class );
                    intent.putExtra( "position",position );
                    intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                    startActivity(intent);
                    overridePendingTransition( 0,0 );
                }
            });
        }
        catch ( Exception e ){e.printStackTrace();}
    }
}

我如何使我的代码如此轻巧的工作非常顺利.平滑的表现意义,适当声明变量,循环,垃圾收集使用等?

解决方法

看看 this question and all its answers,谈到Android上的性能优化很多.
原文链接:https://www.f2er.com/android/311298.html

猜你在找的Android相关文章