gpt4 book ai didi

java - Android 对话框和内存

转载 作者:行者123 更新时间:2023-11-30 09:30:56 26 4
gpt4 key购买 nike

案例 1:

public class NewEntryActivity 
{

public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.xxxx);


//my_button_1
my_button_1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

final Dialog dialog = new Dialog(NewEntryActivity.this);

dialog.setContentView(R.layout.abcabc);

dialog.show();

// On click of OK button in this dialog it will DISMISS the dialog. ( NOT remove )

}
}

//my_button_2
my_button_2.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {

final Dialog dialog = new Dialog(NewEntryActivity.this);

dialog.setContentView(R.layout.xyzxyz);

dialog.show();

// On click of OK button in this dialog it will DISMISS the dialog. ( NOT remove )

}


}

}
}

案例 2:

public class NewEntryActivity 
{

public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.xxxx);


final Dialog dialog1 = new Dialog(NewEntryActivity.this);
final Dialog dialog2 = new Dialog(NewEntryActivity.this);

dialog1.setContentView(R.layout.abcabc);
dialog2.setContentView(R.layout.xyzxyz);

//my_button_1
my_button_1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

dialog1.show();

}
}

}


}

在案例 2 中,我的对话框中已经设置了内容 View 。只需单击按钮即可显示/关闭。

所以我的问题是,第一种情况会释放一些内存,还是会产生同样的效果?

最佳答案

这仅取决于您的应用消耗了多少内存,尤其是在此 Activity 中,但情况 1 似乎不错。

关于java - Android 对话框和内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13066641/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com