这是我的代码,用于使用自定义邮件功能发送邮件查询,问题是当我在发送邮件时应用渐进式对话时,我的查询已发送给我们的团队。"显示之后"发送查询时出现问题。"吐司也显示,但邮件已正确发送。 请帮我解决这个问题。
JAVA
/ dialog = ProgressDialog.show(ProjectEnquiry.this, "",
// "Sending enquiry...", true);
progressDialog = ProgressDialog.show(ProjectEnquiry.this, "Please wait ...", "Task in progress ...", true);
progressDialog.setCancelable(true);
new Thread(new Runnable() {
@Override
public void run() {
try {
String msgbody="Name : "+name.getText().toString()+"\n\nMobile Number : "+mobile.getText().toString()+"\n\nProject Name: "+s1.getSelectedItem().toString()+"\n\nType of apartment: "+s2.getSelectedItem().toString()+"\n";
Mail m = new Mail("munnasuriya@gmail.com", "qafhsanib");
String[] toArr = {"ashfaqbinnazar@yahoo.com"};
//m.send()
m.setTo(toArr);
m.setFrom("munnasuriya@gmail.com");
m.setSubject("Project Enquiry(Android Application)");
m.setBody(msgbody);
// Toast.makeText(getApplicationContext(), "okkk setting.", Toast.LENGTH_LONG).show();
try {
// m.addAttachment("/sdcard/filelocation");
if(m.send()) {
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Your enquiry has been sent to our team.", Toast.LENGTH_LONG).show();
}
});
//Intent intent= new Intent(ProjectEnquiry.this, MainActivity.class);
//startActivity(intent);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
ProjectEnquiry.this.startActivity(new Intent(ProjectEnquiry.this,MainActivity.class));
}
}, 3000);
} else {
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
Toast.makeText(ProjectEnquiry.this, "Your enquiry was not sent.", Toast.LENGTH_LONG).show();
}
});
}
} catch(Exception e) {
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
Toast.makeText(ProjectEnquiry.this, "There was a problem sending the enquiry.", Toast.LENGTH_LONG).show();
}
});
}
Thread.sleep(3000); // Let's wait for some time
} catch (Exception e) {
}
progressDialog.dismiss();
}
}).start();
答案 0 :(得分:1)
如果代码部分改变了这一点:
if(m.send()) {
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Your enquiry has been sent to our team.", Toast.LENGTH_LONG).show();
}
});
//Intent intent= new Intent(ProjectEnquiry.this, MainActivity.class);
//startActivity(intent);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
ProjectEnquiry.this.startActivity(new Intent(ProjectEnquiry.this,MainActivity.class));
}
}, 3000);
}
到此:
if(m.send()) {
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Your enquiry has been sent to our team.", Toast.LENGTH_LONG).show();
//Intent intent= new Intent(ProjectEnquiry.this, MainActivity.class);
//startActivity(intent);
ProjectEnquiry.this.startActivity(new Intent(ProjectEnquiry.this,MainActivity.class));
}
});
}
如果您有任何问题,请告诉我。