2
我创建了一个与服务器异步通信的应用程序。当应用程序发出服务器请求时,会创建一个带有“加载”通知的新对话框(活动)。主要活动实现处理服务器响应的方法,并且当主要活动从服务器接收到答案时,我想关闭前台活动。Android:如何从活动活动关闭前台活动?
通知对话框创建以下方式:
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)。