我有一个测试变量是否为null的应用程序。如果为null,则i显示一个设置变量的对话框。问题是当框显示时,活动继续执行。我希望我的活动挂起并等待对话框的结果然后恢复。我怎么能实现这个目标呢?
if(nfcscannerapplication.getCompId() == null ||
nfcscannerapplication.getCompId().trim().equalsIgnoreCase("null")){
Log.e(TAG, "compid null***********");
showPasswordDialogBox();
}else{
Log.e(TAG, "compid not null***********");
String[] paramsCompOpt = new String[]{nfcscannerapplication.getCompId()};
AsyncGetCompanyOptions agco = new AsyncGetCompanyOptions();
agco.execute(paramsCompOpt);
}
答案 0 :(得分:1)
尝试类似:
preMethod() {
// Your actual code...
if(nfcscannerapplication.getCompId() == null || nfcscannerapplication.getCompId().trim().equalsIgnoreCase("null")){
Log.e(TAG, "compid null***********");
// Call postMethod() once the variable is set in the Dialog box**
showPasswordDialogBox();
} else{
Log.e(TAG, "compid not null***********");
String[] paramsCompOpt = new String[]{nfcscannerapplication.getCompId()};
AsyncGetCompanyOptions agco = new AsyncGetCompanyOptions();
agco.execute(paramsCompOpt);
postMethod();
}
}
postMethod() {
// Code to execute when the variable is set
...
}
答案 1 :(得分:0)
您可以将需要变量的代码放在私有方法中。然后,如果变量已正确初始化,则调用该方法。或者,如果未正确初始化,则显示对话框并在on close处理程序中调用private方法。