0

Android エミュレーターでアプリを実行すると、log-cat から、70 フレーム (アプリの起動開始時) がスキップされ、メイン スレッドでの処理が多すぎる可能性があることがわかります。負荷を分散したり、アプリのパフォーマンスを向上させたりするにはどうすればよいですか? 起動時にロード画面が必要ですか。

これは私の打ち上げ活動です。

package com.the.maze;

import android.app.ListActivity;  
import android.content.Intent;  
import android.os.Bundle;  
import android.view.View;  
import android.widget.ArrayAdapter;  
import android.widget.ListView;

    public class TheMazeActivity extends ListActivity{  
            String list[]={"New Game","Highscores","How to play","Settings","About"};
            Class classes[]={GameActivity.class,null,Instructions.class,null,null};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, list));

    }
        @Override
        protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        try{
        Intent intent= new Intent(TheMazeActivity.this,classes[position]);
        startActivity(intent);
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}
4

1 に答える 1

0

私が提案できる改善点はそれほど多くなく、コード内での重い計算は見られません(もしあれば!)。とにかくこれらは私の提案です:

public class TheMazeActivity extends ListActivity{
    //make them static final  
    private static final String[] list={"New Game","Highscores","How to play","Settings","About"};
    private stativc final Class[] classes={GameActivity.class,null,Instructions.class,null,null};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, list));
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        //no need for try catch, if you can perfectly find out, when to trigger!
        if [classes[position] != null){
            Intent intent= new Intent(TheMazeActivity.this,classes[position]);
            startActivity(intent);
        }
   }
}

ただし、これらの変更はいわゆるマイクロ最適化にすぎないことに注意してください。

于 2012-07-18T12:45:25.047 に答える