アプリケーションを実行すると、電話のCPU使用率が最大40%になります。
final String position = String.format("%02d:%02d:%02d", time.getHours(), time.getMinutes(),
time.getSeconds());
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
c.mTxtPosition.setText(position);
...
setTextメソッドをコメントアウトすることにより、CPU使用率は予想されるレベルの約4%に低下します。このメソッドは毎秒呼び出され、同じ負荷超過を引き起こすことなくImageViews、CustomViews...を更新します。CPU使用率に加えて、dalvikは、setText()を呼び出すだけで、約10〜1000個のオブジェクトのガベージコレクションを常に報告します。
次のようなトレースファイルを作成します。
Debug.startMethodTracing("setText");
c.mTxtPosition.setText(position);
Debug.stopMethodTracing();
traceviewは、以下のメソッドをそれぞれの専用CPU%でトップ5としてリストします。
- ViewParent.invalidateChildInParent(16%)
- View.requestLayout(11%)
- ViewGroup.invalidateChild(9%)
- TextView.setText(7%)
- トップレベル(6%)
誰かがこれについての説明がありますか?