【发布时间】:2010-12-02 00:12:25
【问题描述】:
我创建了一个与服务器异步通信的应用程序。当应用程序向服务器发出请求时,会创建一个带有“正在加载”通知的新对话框(活动)。主要活动实现了处理服务器响应的方法,我想在主要活动收到来自服务器的答复时关闭前台活动。
通知对话框的创建方式如下:
private void showServerRequestDialog(String actionLabel){
Intent intent = new Intent(this, DlgServerRequest.class);
intent.putExtra(SERVER_REQUEST_ACTION, actionLabel);
startActivity(intent);
}
所以当用户尝试验证时,会调用以下方法:
private void authenticateUser(String IMEI, String username, String password){
mEncoderConnection.authenticateRequest(IMEI, username, password);
showServerRequestDialog("Authenticating...");
}
onAuthenticateResponse 处理身份验证响应:
public void onAuthenticateResponse(AuthenticateResponse pkg) {
//code for response handling
//TODO: close ServerRequestDialog
}
}
如果有人能提出一种在执行 onAuthenticateUser() 时关闭通知对话框 (DlgServerRequest) 的方法,我将不胜感激。
【问题讨论】:
标签: android android-activity subactivity