私は最近、デバイスを頻繁に変更する root ユーザー向けにこのアプリケーションを作成しました。
ここで、アプリケーションのインストール サイズに関する非常に奇妙な動作に気付きました。
ビューが XML ファイルから初期化されている通常のアクティビティを使用した場合、サイズは715 kb
.
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.main_layout);
executeEvents = new ExecuteEvents(this);
display = (TextView) findViewById(R.id.display);
powermenu = (Button) findViewById(R.id.powermenu);
turnoffscreen = (Button) findViewById(R.id.turnscreenoff);
mapButton = (ImageButton) findViewById(R.id.mapButton);
SP = getSharedPreferences(PBConstants.Power_Button_SP, MODE_MULTI_PROCESS);
if(SP.contains(PBConstants.INPUT_DEVICE_TAG))
display.setText(getResources().getString(R.string.configured));
mapButton.setOnClickListener(this);
powermenu.setOnClickListener(this);
turnoffscreen.setOnClickListener(this);
}
XMLファイルにウィジェットを含むビューを設定して作成されたダイアログに切り替えた後。アプリのサイズは になり200kb
ました。
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
//setContentView(R.layout.main_layout);
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.main_layout, null);
executeEvents = new ExecuteEvents(this);
display = (TextView) view.findViewById(R.id.display);
powermenu = (Button) view.findViewById(R.id.powermenu);
turnoffscreen = (Button) view.findViewById(R.id.turnscreenoff);
mapButton = (ImageButton) view.findViewById(R.id.mapButton);
SP = getSharedPreferences(PBConstants.Power_Button_SP, MODE_MULTI_PROCESS);
if(SP.contains(PBConstants.INPUT_DEVICE_TAG))
display.setText(getResources().getString(R.string.configured));
mapButton.setOnClickListener(this);
powermenu.setOnClickListener(this);
turnoffscreen.setOnClickListener(this);
Dialog dialog = new Dialog(this);
dialog.setContentView(view);
dialog.setTitle(getResources().getString(R.string.app_name));
dialog.show();
}
これ80kb
を使用すると、次のようになりました。
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
dialog = new Dialog(this);
dialog.setContentView(R.layout.main_layout);
executeEvents = new ExecuteEvents(this);
display = (TextView) dialog.findViewById(R.id.display);
powermenu = (Button) dialog.findViewById(R.id.powermenu);
turnoffscreen = (Button) dialog.findViewById(R.id.turnscreenoff);
mapButton = (ImageButton) dialog.findViewById(R.id.mapButton);
SP = getSharedPreferences(PBConstants.Power_Button_SP, MODE_MULTI_PROCESS);
if(SP.contains(PBConstants.INPUT_DEVICE_TAG))
display.setText(getString(R.string.configured));
mapButton.setOnClickListener(this);
powermenu.setOnClickListener(this);
turnoffscreen.setOnClickListener(this);
dialog.setTitle(getString(R.string.app_name));
dialog.show();
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
dialog.dismiss();
MainActivity.this.finish();
}
});
}
また、最後のスタイルのコード (1 つ) でアニメーションを追加しようとしたときに、アプリケーション サイズの別の奇妙な変化に気付きました80kb
。アプリのサイズが大きくなりました1 MB
。これは、アニメーションを初期化し、ボタンがクリックされたときに呼び出す方法です:
private static final ScaleAnimation animation = new ScaleAnimation(1, .95f, 1, .95f, Animation.RELATIVE_TO_SELF, (float)0.5, Animation.RELATIVE_TO_SELF, (float)0.5);//declared as global variable
onCreate メソッド内:
animation.setDuration(1000);
animation.setFillAfter(false);
その後、次のように呼び出しましたonClickListener
:
mapButton.startAnimation(animation);
新しいリソースを追加せず、コードのスタイルを変更しただけなのに、なぜアプリケーションのサイズが大幅に変化するのでしょうか? ダイアログに存在するウィジェットを初期化する方法に大きな違いがあるのはどこですか? 追加した方法でアニメーションを追加すると、大きな違いがあるのはなぜですか?
フォローアップの質問:
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.main_layout);
executeEvents = new ExecuteEvents(this);
display = (TextView) this.findViewById(R.id.display);
powermenu = (Button) this.findViewById(R.id.powermenu);
turnoffscreen = (Button) this.findViewById(R.id.turnscreenoff);
mapButton = (ImageButton) this.findViewById(R.id.mapButton);
SP = getSharedPreferences(PBConstants.Power_Button_SP, MODE_MULTI_PROCESS);
if(SP.contains(PBConstants.INPUT_DEVICE_TAG))
display.setText(getResources().getString(R.string.configured));
mapButton.setOnClickListener(this);
powermenu.setOnClickListener(this);
turnoffscreen.setOnClickListener(this);
}
投機
これは、インポートされたパッケージまたはクラスが原因でしょうか? animation
少なくとも質問のビットには意味があります。
ビューが初期化されるコンテキストを追加すると、メモリ使用量が削減されますか?