gpt4 book ai didi

android - 如果有先前 Activity 的返回数据来通知用户,如何创建警报对话框?

转载 作者:行者123 更新时间:2023-11-29 23:55:13 25 4
gpt4 key购买 nike

我正在尝试向我的项目添加警报对话框,以通知用户是否有来自先前 Activity 的返回数据,但是在我的方法中,if 语句有问题或缺少某些内容,即使没有返回数据,警报对话框也始终存在弹出任何建议或想法将不胜感激。

//This part is my method
public void dataReceive(){
//requesting data from server
//adding parameters
RequestParams params = new RequestParams();
SessionManager sessionManager = new SessionManager(this);
HashMap<String, String> user = sessionManager.getUserDetails();
if (user != null) {
String uid = user.get(SessionManager.USER_ID);
params.put("user_id", uid);
}
try{
String name = user.get(SessionManager.KEY_NAME);

username = name;

}catch (Exception e){

}
//This part is my approach
Bundle tokens = this.getIntent().getExtras();
if(tokens != null) {
final PendingRequestPojo pendingRequestPojo = new PendingRequestPojo();
responseid = tokens.getString("responseid");
requestid = tokens.getString("requestid");
//Toast.makeText(getApplicationContext(), "responseid :" + responseid + "\nrequestid : " +
//requestid, Toast.LENGTH_SHORT).show();

alert = new AlertDialog.Builder(SplashActivity.this);
alert.setTitle("ThirdWheel Payment Response");
alert.setIcon(R.drawable.thinrdwheel_alert);
alert.setMessage("Your Payment Was Successfull" + " " + username +
"Thank you, we Hope you can ride with us Again ");
alert.setCancelable(true);
alert.setPositiveButton("Thanks", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
changement();
Updatepayment(pendingRequestPojo.getRide_id(), "PAID");
}
}).show();

} else {

changement();
}
}

最佳答案

您的代码必须如下所示

 public void dataReceive(){ 
//requesting data from server
//adding parameters
RequestParams params = new RequestParams();
SessionManager sessionManager = new SessionManager(this);
HashMap<String, String> user = sessionManager.getUserDetails();
if (user != null) {
String uid = user.get(SessionManager.USER_ID);
params.put("user_id", uid);
}
try{
String name = user.get(SessionManager.KEY_NAME);

username = name;

}catch (Exception e){

}
//This part is my approach
Bundle tokens = this.getIntent().getExtras();
if(tokens != null &&
tokens.containsKey("responseid") && tokens.containsKey("requestid")) {
final PendingRequestPojo pendingRequestPojo = new PendingRequestPojo();
responseid = tokens.getString("responseid");
requestid = tokens.getString("requestid");
//Toast.makeText(getApplicationContext(), "responseid :" + responseid + "\nrequestid : " +
//requestid, Toast.LENGTH_SHORT).show();

alert = new AlertDialog.Builder(SplashActivity.this);
alert.setTitle("ThirdWheel Payment Response");
alert.setIcon(R.drawable.thinrdwheel_alert);
alert.setMessage("Your Payment Was Successfull" + " " + username +
"Thank you, we Hope you can ride with us Again ");
alert.setCancelable(true);
alert.setPositiveButton("Thanks", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
changement();
Updatepayment(pendingRequestPojo.getRide_id(), "PAID");
}
}).show();

} else {

changement();
}
}

关于android - 如果有先前 Activity 的返回数据来通知用户,如何创建警报对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50442781/

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