情况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 )
}
}
}
}
案例二:
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();
}
}
}
}
在 CASE 2 中,我已经在其中设置了内容视图的对话框。只需单击按钮即可显示/关闭。
所以我的问题是,第一种情况会释放一些内存,还是会产生相同的效果?